CALayer简介
1、CALayer一般作为UIView的容器而使用
2、CALayer是一个管理着图片载体(image-based content)的层结构
3、直接修改单独创建出的CALayer的属性可以出发隐式动画
4、UIView中的CALayer动画必须显示出发才能生效
CALayer实现自定义进度条
| - (void)viewDidLoad { [super viewDidLoad]; 
 UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 3)]; containerView.backgroundColor = [UIColor redColor]; 
 [self.view addSubview:containerView]; 
 //修改该容器layer的相关值 // containerView.layer.frame = CGRectMake(0, 0, 200, 200); // containerView.layer.backgroundColor = [UIColor greenColor].CGColor; 
 //创建一个独立的layer self.layer = [CALayer layer]; //刚开始的进度为0 self.layer.frame = CGRectMake(0, 0, 20, 3); self.layer.backgroundColor = [UIColor greenColor].CGColor; 
 [containerView.layer addSublayer:self.layer]; 
 [self performSelector:@selector(layerAnimation) withObject:nil afterDelay:3.0]; 
 } - (void)layerAnimation { NSLog(@"修改了layer的frame值"); //执行了隐式动画 self.layer.frame = CGRectMake(0, 0, 100, 3); self.layer.backgroundColor = [UIColor blackColor].CGColor; } | 
原文:http://my.oschina.net/hejunbinlan/blog/469519