博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS-CALayer图片淡入淡出动画
阅读量:7069 次
发布时间:2019-06-28

本文共 1677 字,大约阅读时间需要 5 分钟。

#import 
"
ViewController.h
"
@interface ViewController ()
@property (nonatomic,strong)CALayer *imageLayer;
@end
@implementation ViewController
- (
void)viewDidLoad {
    [super viewDidLoad];
    UIImage *image1 = [UIImage imageNamed:
@"
test1.jpg
"];
   
    
//
可以显示图片类容,layer是view的载体
//
    self.view.layer.contents = (__bridge id)(image.CGImage);
    
    
//
创建出图片layer
    self.imageLayer = [CALayer layer];
    self.imageLayer.frame = self.view.bounds;
    [self.view.layer addSublayer:self.imageLayer];
    
    self.imageLayer.contents = (__bridge 
id)(image1.CGImage);
    [self performSelector:@selector(imageAnimation) withObject:nil afterDelay:
3];
}
- (
void)imageAnimation {
    
    
//
隐式动画
     UIImage *image2 = [UIImage imageNamed:
@"
test2.jpg
"];
    
//
 self.imageLayer.contents = (__bridge id)(image2.CGImage);
    CABasicAnimation *contentsAnimation = [CABasicAnimation animationWithKeyPath:
@"
contens
"];
    contentsAnimation.fromValue = self.imageLayer.contents;
//
原始图片
    contentsAnimation.toValue = (__bridge 
id)(image2.CGImage);
//
切换后图片
    contentsAnimation.duration = 
3.f;
    
    CABasicAnimation *boundsAnimation = [CABasicAnimation animationWithKeyPath:
@"
bounds
"];
    boundsAnimation.fromValue = [NSValue valueWithCGRect:self.imageLayer.bounds];
    boundsAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(
10
100
200
200)];
    boundsAnimation.duration = 
3.f;
    
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = @[contentsAnimation,boundsAnimation];
    group.duration = 
3.f;
    
//
设置layer动画结束后的值否则会回复东湖钱的状态
    self.imageLayer.contents = (__bridge 
id)(image2.CGImage);
    self.imageLayer.bounds = CGRectMake(
10
100
200
200);
    [self.imageLayer addAnimation:group forKey:nil];
    
}

转载于:https://www.cnblogs.com/hxwj/p/4666036.html

你可能感兴趣的文章
关于笔记本电脑网卡出问题的简单解决
查看>>
IPV4与IPV6表示方法
查看>>
桌面支持--不懂不要乱动-尤其是别人的东西
查看>>
hadoop集群上运行自定义wordcount
查看>>
Linux条件测试
查看>>
图形图表设计软件Edraw Max更新至v9.0,新增10000+符号和模板丨限时8.5折
查看>>
关于Dialog引起的报错“未附加到窗口管理器”
查看>>
memecache过期策略
查看>>
3.1 用户配置文件和密码配置文件
查看>>
高并发之Nginx的限流
查看>>
简单的短信验证功能的实现
查看>>
众筹智能合约实现代码
查看>>
「续集」Sass简易指南:多风格编译和运行以及文件注释
查看>>
JAVA导出EXCEL
查看>>
11.14/11.15 Apache和PHP结合 11.16/11.17 Apache默认虚拟主机
查看>>
TeeChart Pro VCL/FMX教程(六):使用系列(一)
查看>>
Dubbo分析之Cluster层
查看>>
Titan Framework MongoDB深入理解3
查看>>
iOS核心动画笔记2-寄宿图
查看>>
几种不同类型网站内容优化切入点
查看>>