iOS开发核心动画之图片折叠/渐变层

摘要:
1.显示效果2.代码实现#import“ViewController.h”@interfaceViewController()@property(弱,非原子)IBOutletUIImageView*topV@property属性(弱,非原子)IBOutletU

1. 显示效果

iOS开发核心动画之图片折叠/渐变层第1张 

2. 代码实现

#import "ViewController.h"


@interface ViewController ()


@property (weaknonatomicIBOutlet UIImageView *topV;


@property (weaknonatomicIBOutlet UIImageView *bottomV;



@property (weaknonatomicIBOutlet UIView *touchView;


/** 渐变层 */

@property (nonatomicweakCAGradientLayer *gradient;


@end


@implementation ViewController


- (void)viewDidLoad {

    

    [super viewDidLoad];

    

    // 显示上半部分

    self.topV.layer.contentsRect = CGRectMake(0010.5);

    self.topV.layer.anchorPoint = CGPointMake(0.51);

    

    // 只显示下半部分

    self.bottomV.layer.contentsRect = CGRectMake(00.510.5);

    self.bottomV.layer.anchorPoint = CGPointMake(0.50);

    

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer allocinitWithTarget:self action:@selector(pan:)];

    [self.touchView addGestureRecognizer:pan];

    

    // 渐变层

    CAGradientLayer *gradient = [CAGradientLayer layer];

    gradient.frame = self.bottomV.bounds;

    // 设置渐变颜色

    gradient.colors = @[(id)[UIColor clearColor].CGColor,(id)[UIColor blackColor].CGColor];

    

    // 设置图层的不透明度

    gradient.opacity = 0;

    self.gradient = gradient;

    [self.bottomV.layer addSublayer:gradient];

    

}


- (void)pan:(UIPanGestureRecognizer *)pan

{

    CGPoint offset = [pan translationInView:self.touchView];

    

    CGFloat angle = offset.y * M_PI / 200.0;

    

    CATransform3D transform = CATransform3DIdentity;

    transform.m34 = -1 / 300.0;

    

    self.topV.layer.transform = CATransform3DRotate(transform, -angle, 100);

    

//    [pan setTranslation:CGPointZero inView:self.touchView];

    

    // 修改渐变层的不透明度

    self.gradient.opacity = offset.y / 200.0;

    

    // 判断手指松开上面的图片复位

    if (pan.state == UIGestureRecognizerStateEnded) {

        self.gradient.opacity = 0;

        

        //Duration:动画的执行时长

        //delay:动画延迟执行的时间

        //SpringWithDamping:弹性系数.

        //SpringVelocity:弹性的初始速度.

        [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.25 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{

            self.topV.layer.transform = CATransform3DIdentity;

        } completion:^(BOOL finished) {

            

        }];

    }

    

}



//渐变层

- (void)gradientLayer{

    CAGradientLayer *gradient = [CAGradientLayer layer];

    gradient.frame = self.bottomV.bounds;

    //设置渐变的颜色

    gradient.colors = @[(id)[UIColor redColor].CGColor,(id)[UIColor greenColor].CGColor,(id)[UIColor blueColor].CGColor];

    

    //修改渐变的方向

    gradient.startPoint = CGPointMake(00);

    gradient.endPoint = CGPointMake(10);

    //设置渐变的起始位置(从哪点开始渐变到下一个颜色)

    gradient.locations = @[@0.3,@0.7];

    [self.bottomV.layer addSublayer:gradient];

}




免责声明:文章转载自《iOS开发核心动画之图片折叠/渐变层》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇mybatis的知识点总结【转】你应该知道的 10 个 VirtualBox 技巧与高级特性下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

DOCKER 从入门到放弃(二)

搜索镜像 从docker官方镜像仓库搜索镜像 docker search [OPTIONS] TERM OPTIONS: --automated :只显示自动创建的镜像,默认值为fasle --filter,-f :显示过滤后的搜索结果 --limit :显示的最大搜索结果,默认值为25 --no-trunc : 显示完整的镜像描述,默认值为fasle...

LTP介绍

1.LTP介绍    LTP--linut test project ,ltp套件是由Linux Test Project所开发的一套系统測试套件。它基于系统资源的利用率统计开发了一个測试的组合,为系统提供足够的压力。    通过压力測试来推断系统的稳定性和可靠性。    压力測试是一种破坏性的測试,即系统在非正常的、超负荷的条件下的执行情况 。用来评...

Cesium 做汉化的另一种思路。[转]

汉化肯定是最基础又必须做的一个功能,要不界面上按钮toolTip都是英文,都不知道怎么和客户交代。 因为Cesium 里面的一些按钮的toolTip提示都是硬编码在里面的。 所以好多小伙伴们做汉化通常是直接修改源码然后编译使用。 如果仅仅是为了汉化去编译源代码,我觉得有些不那么合适,你想想每次你升级Cesium版本的时候,这些重复劳动是不是很烦。 首先这个...