iOS-CALayer图片淡入淡出动画
2015-07-21 23:52
489 查看
#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];
}
@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];
}
相关文章推荐
- iOS上获取文件md5的方法
- iOS项目中工作空间Workspaces概念的理解
- 提高iOS开发效率的方法和工具
- Xcode 6制作动态及静态Framework
- 苹果开发 笔记(52)
- iOS-CALayer实现简单进度条
- iOS开发中关于nslog的几种流行做法小结
- mac 制作 ios 的 usb 启动盘
- iOS编程:学习篇(七)
- iOS-CALayer
- iOS内存管理之浅见
- swif关于ios生命管理周期
- iOS 获取手机 唯一标识
- 开发第一个iOS项目 Hello iOS
- 安装iOS开发环境Xcode
- iOS初学者
- iOS开发 ----- C文件读写,以及字符串分割
- iOS 用代码添加模态视图
- iOS开发-使用第三方库AFNetWorking解析JSON和XML数据
- iOS开发 ----- 关于char *的赋值和字符串之间的复制问题以及sizeof strlen