<极客学院>视频教程学习笔记-iOS中CALayer的使用
2015-07-24 23:31
567 查看
<1>CALayer简介
1、CALayer一般作为UIView的容器而使用。
2、CALayer是一个管理者图片载体(image-based content)的层结构
3、直接修改单独创建出的CALayer的属性可以触发隐式动画
4、UIView中的CALayer动画必须显式触发才能生效
开篇代码练习:
继续努力敲代码:
1、CALayer一般作为UIView的容器而使用。
2、CALayer是一个管理者图片载体(image-based content)的层结构
3、直接修改单独创建出的CALayer的属性可以触发隐式动画
4、UIView中的CALayer动画必须显式触发才能生效
开篇代码练习:
#import "ViewController.h" @interface ViewController () //2单独创建一个layer @property (nonatomic,strong) CALayer *layer; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //1创建一个容器View UIView *containerview = [[UIView alloc] initWithFrame:CGRectMake(50, 200, 100, 3)]; containerview.backgroundColor = [UIColor blueColor]; [self.view addSubview:containerview]; //3使用并设置layer的相关值 self.layer = [CALayer layer]; [self.layer setFrame:CGRectMake(0, 0, 50, 3)]; self.layer.backgroundColor = [UIColor redColor].CGColor;//别忘了最后面还要一个 .CGColor [containerview.layer addSublayer:self.layer]; } @end
继续努力敲代码:
#import "ViewController.h" @interface ViewController () //创建一个独立的layer @property (nonatomic,strong) CALayer *layer; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //创建一个UIView作为父容器 UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 200, 3)]; containerView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:containerView]; //layer self.layer = [CALayer layer]; self.layer.frame = CGRectMake(0, 0, 10, 3); self.layer.backgroundColor = [UIColor blueColor].CGColor; [containerView.layer addSublayer:self.layer]; // 使用了消息处理方法,并添加layerAnimatiion方法 [self performSelector:@selector(layerAnimation) withObject:nil afterDelay:3.f]; } -(void)layerAnimation{ NSLog(@"修改了layer"); self.layer.frame = CGRectMake(0, 0, 150, 3); } @end
相关文章推荐
- ios autolayerout
- 常用方法-各种常用方法封装
- iOS之通讯录1
- iOS开发中的压缩以及解压
- iOS中大文件下载(单线程下载)
- IOS学习 nib加载相关内容(1)
- IOS html解析
- iOS自定义tabbar
- iOS 学习资料整理
- iOS获取文件夹中存储空间的大小、手机剩余空间大小、手机总空间大小 工具
- iOS单元测试编码规范
- iOS如何测试单例?
- iOS 什么时候用 copy、weak、strong、assign?
- iOS单元测试编码规范
- IOS开发笔记之二十九——一个野指针引起的bug
- iOS指针第一天
- 与大家讨论如何用opencore amr在iOS上decode(已解决)
- iOS 类别和扩展(Categories和Extensions)
- 关于IOS9
- iOS中几种数据持久化方案