iOS开发概述 - 14.CALayer隐式动画
来源:互联网 发布:深入java虚拟机 编辑:程序博客网 时间:2024/04/29 10:05
1.隐式动画概述
- 每一个UIView内部都默认关联着一个CALayer,我们可用称这个Layer为Root Layer(根层)
- 所有的非Root Layer,也就是手动创建的CALayer对象,都存在着隐式动画
- 当对非Root Layer的部分属性进行修改时,默认会自动产生一些动画效果,这种效果我们称之为隐式动画
- 这些属性称为Animatable Properties(可动画属性),在系统头文件属性描述中有Animatable的都可以实现动画效果
-列举几个常见的Animatable Properties:- bounds:用于设置CALayer的宽度和高度。修改这个属性会产生缩放动画
- backgroundColor:用于设置CALayer的背景色。修改这个属性会产生背景色的渐变动画
- position:用于设置CALayer的位置。修改这个属性会产生平移动画
2.隐式动画代码示例
- 效果图
- 代码示例
@interface ViewController ()@property (nonatomic, weak) CALayer *imageLayer;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // 创建新图层 CALayer *layer = [CALayer layer]; _imageLayer = layer; // 设置图层背景颜色 layer.backgroundColor = [UIColor redColor].CGColor; // 设置图层frame layer.frame = CGRectMake(100, 100, 100, 100); // 设置图层内容 layer.contents = (id)[UIImage imageNamed:@"阿狸头像"].CGImage; // 添加到根层 [self.view.layer addSublayer:layer];}-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // 开启事务 [CATransaction begin]; // 设置隐式动画属性 // 设置隐式动画失效// [CATransaction setDisableActions:YES]; // 设置隐式动画持续时间 [CATransaction setAnimationDuration:1.0]; // 属性描述中有Animatable的属性都可以实现动画效果 // 设置图层隐式动画属性 // 背景颜色,随机颜色 _imageLayer.backgroundColor = [self randomColor].CGColor; // 位置属性 _imageLayer.position = CGPointMake(arc4random_uniform(375), arc4random_uniform(500)); // 设置圆角属性 _imageLayer.cornerRadius = arc4random_uniform(51); // 根据圆角裁剪图片 _imageLayer.masksToBounds = YES; // 设置边框宽度 _imageLayer.borderWidth = arc4random_uniform(10); // 设置边框颜色 _imageLayer.borderColor = [self randomColor].CGColor; // 设置阴影效果 _imageLayer.shadowOpacity = YES; _imageLayer.shadowColor = [self randomColor].CGColor; _imageLayer.shadowRadius = arc4random_uniform(20); // 提交事务 [CATransaction commit];}// 生成随机颜色-(UIColor *)randomColor{ CGFloat r = arc4random_uniform(256); CGFloat g = arc4random_uniform(256); CGFloat b = arc4random_uniform(256); return [UIColor colorWithRed:r / 255.0 green:g / 255.0 blue:b / 255.0 alpha:1];}
0 0
- iOS开发概述 - 14.CALayer隐式动画
- iOS CALayer 隐式动画
- iOS CALayer隐式动画
- iOS核心动画之CALayer-隐式动画
- iOS开发UI篇—CAlayer层的属性(position、anchorPoint) 和隐式动画
- iOS开发UI篇-CALayer层的属性、隐式动画
- iOS开发UI篇—CAlayer层的属性(layer的隐式动画)
- iOS开发系列-动画绘图CALayer
- ios-day18-04(图层CALayer的隐式动画)
- 三 iOS之 CALayer的隐式动画
- iOS动画之CALayer
- iOS核心动画 CALayer
- iOS CALayer动画
- IOS CALayer 动画
- CALayer的隐式动画
- CALayer 的隐式动画
- XMG CALayer隐式动画
- CALayer关闭隐式动画
- 随想
- druid 数据源的配置
- Visual C#2010学习笔记三之return返回值的使用
- 嵌入式MCGS项目记录,modbus-rtu协议
- OpenCV学习笔记(0)—— 摄像机模型与标定1
- iOS开发概述 - 14.CALayer隐式动画
- CSS学习笔记----(三)
- Eclipse下Android项目结构介绍
- 学习MongoDB--(1):MongoDB简介
- Java基础-Map接口及其实现
- 求分数--推荐指数(★★★★★)
- 20150805训练题
- 黑马程序员 oc随记 类方法与对象方法
- poj 1379