CALayer CABasicAnimation
CALayer是UIView可以响应事件。一般来说,layer可以有两种用途:一是对view相关属性的设置,包括圆角、阴影、边框等参数;二是实现对view的动画操控。
因此对一个view进行core animation动画,本质上是对该view的.layer进行动画操纵。
1.CALayer常见属性
新建图层
CALayer * layer = [CALayer layer];
图层颜色
layer.backgroundColor = [UIColor redColor].CGColor;
图层大小
layer.bounds = CGRectMake(0, 0, 100, 100);
图层锚点
layer.anchorPoint = CGPointMake(0, 0);
图层位置
layer.position = self.view.center;
圆角半径
layer.cornerRadius = 50;
边框宽度
layer.borderWidth = 2;
边框颜色
layer.borderColor = [UIColor blackColor].CGColor;
添加图层
[self.view.layer addSublayer:layer];
2.CALayer有2个非常重要的属性:position和anchorPoint
@property CGPoint position;
用来设置CALayer在父层中的位置
以父层的左上角为原点(0, 0)
@property CGPoint anchorPoint;
称为“定位点”、“锚点”
决定着CALayer身上的哪个点会在position属性所指的位置
以自己的左上角为原点(0, 0)
它的x、y取值范围都是0~1,默认值为(0.5, 0.5)
layer.anchorPoint = CGPointMake(0, 0);

layer.anchorPoint = CGPointMake(0.5, 0.5);

layer.anchorPoint = CGPointMake(1, 1);

3.改变transform的动画
旋转
layer.transform = CATransform3DRotate(_layer.transform, 10/180.0*M_PI, 1, 1, 1);
放大缩小
layer.transform = CATransform3DScale(_layer.transform, 2, 2, 2);
平移
layer.transform = CATransform3DTranslate(_layer.transform, 10, 10, 0);
4.CABasicAnimation
CALayer *Layer = [[CALayer alloc] init]; Layer.backgroundColor = [UIColor blueColor].CGColor;
Layer.frame = CGRectMake(100, 100, 50, 50);
Layer.cornerRadius = 10;
[self.view.layer addSublayer:scaleLayer];
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];
scaleAnimation.toValue = [NSNumber numberWithFloat:1.5];
scaleAnimation.fillMode = kCAFillModeForwards;最后以什么填充
scaleAnimation.repeatCount = MAXFLOAT;重复次数
scaleAnimation.duration = 1;
[Layer addAnimation:scaleAnimation forKey:nil];
常用的属性有
transform
transform.ratation.z
opacity
position
CALayer *Layer = [[CALayer alloc] init];
Layer.backgroundColor = [UIColor blueColor].CGColor;
Layer.frame = CGRectMake(100, 100, 50, 50);
Layer.cornerRadius = 10;
[self.view.layer addSublayer:Layer];
放大
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];
scaleAnimation.toValue = [NSNumber numberWithFloat:1.5];
渐变
CABasicAnimation * opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.fromValue = @1;
opacityAnimation.toValue = @0;
移动
CABasicAnimation *moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 200)];
旋转
CABasicAnimation *rotateANimation = [CABasicAnimation animationWithKeyPath:@"transform"];
rotateANimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
rotateANimation.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(Layer.transform, M_PI, 0, 0, 1)];
CAAnimationGroup * group = [CAAnimationGroup animation];
group.removedOnCompletion = NO;
group.fillMode = kCAFillModeForwards;
group.repeatCount = MAXFLOAT;
group.duration = 1;
group.animations =@[scaleAnimation,opacityAnimation,moveAnimation,rotateANimation];
[Layer addAnimation:group forKey:nil];
6.补充
再旋转中,上边的写法转换成弧度之后不能转多圈,下面实现转多圈
CABasicAnimation *zrotateANimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
zrotateANimation.fromValue = [NSNumber numberWithFloat:0];
zrotateANimation.toValue = [NSNumber numberWithFloat:M_PI * 4.0];
CALayer CABasicAnimation的更多相关文章
- iOS开发笔记10:圆点缩放动画、强制更新、远程推送加语音提醒及UIView截屏
1.使用CAReplicatorLayer制作等待动画 CALayer+CABasicAnimation可以制作很多简单的动画效果,之前的博客中介绍的“两个动画”,一个是利用一张渐变色图片+CABas ...
- ios 关于动画用法的总结
#import "FirstVC.h" @implementation FirstVC /* 创建xib过程 1 创建xib(名字和类名相同) 2 文件 ...
- iOS Animation具体解释
iOS Animation具体解释 本篇仅仅要解说iOS中动画的使用. Animtion主要分为两类:UIView动画和CoreAnimation动画. UIView动画有UIView属性动画,UIV ...
- CALayer, CoreGraphics与CABasicAnimation介绍
今天我们来看一下CALayer.CoreGraphics和CABasicAnimation.这些东西在处理界面绘制.动画效果上非常有用. 本篇博文就讲介绍CALayer的基本概念,使用CoreGrap ...
- 之一:CABasicAnimation - 基本动画
嗷呜嗷呜嗷呜 // 将视图作为属性方便后面执行多个不同动画 _myView = [[UIView alloc] init]; _myView.layer.position = CGPointMake( ...
- Quartz2D复习(四) --- 图层CALayer和动画CAAnimation
1.CALayer 1).在ios中,能看得见摸得着的东西基本上都是UIView, 比如按钮.文本标签.文本输入框.图标等,这些都是UIView 2).UIView之所以能显示在屏幕上,完全是因为它内 ...
- iOS - CABasicAnimation
代码实例: [1] - (void)pulseClick { //!> 宽和高等比例转换 CABasicAnimation * pulse = [CABasicAnimation animati ...
- iOS开发——UI进阶篇(十七)CALayer,核心动画基本使用
一.CALayer简介 1.CALayer在iOS中,文本输入框.一个图标等等,这些都是UIView你能看得见摸得着的东西基本上都是UIView,比如一个按钮.一个文本标签.一个其实UIView之所以 ...
- CABasicAnimation animationWithKeyPath 一些规定的值
CABasicAnimation animationWithKeyPath Types When using the ‘CABasicAnimation’ from the QuartzCore Fr ...
随机推荐
- Common Table Expressions (CTE)
子查询有时使用起来很麻烦,因为所有的过滤和匹配逻辑都必须集成到子查询表达式中.如果只需要执行一个任务,且只需要使用一次杳询表达式,子查询是很好的选择.但子查询不能被重用,也不能很好地支持多个需求.这个 ...
- iOS_ @property参数分析
@propert的相关参数 因为现在Xcode都是默认使用ARC所以现在分析主要是以ARC为主. 1.@property有哪些参数? 第一组: 内存管理特性 retain assign copy ...
- LP64是什么意思
在64位机器上,如果int是32位,long是64位,pointer也是64位,那么该机器就是LP64的,其中的L表示Long,P表示Pointer,64表示Long和Pointer都是64位的.由于 ...
- 50中制作图表的JS库
参看以下链接:http://www.tuicool.com/articles/FZNjMz
- Ubuntu13.04手动安装nvidia显卡驱动
1. 下载最新版的nVidia驱动,命名为NVIDIA.run. http://www.nvidia.com/page/drivers.html 2.编辑blacklist.conf. sudo ge ...
- Linux的用户和用户组
/etc/group 文件存储了所有的用户和用户组信息 存储格式: 组名:组密码占位符:组编号:组中所有用户 root:x:0: mail:x:12:postfix ... 说明: root: ...
- activiti笔记四 关于部署信息表act_re_deployment
一.简要描述 部署流程定义时需要被持久化保存下来的信息.二.表结构说明 字段名称 字段描述 数据类型 主键 为空 取值说明 ID_ ID_ nvarchar(64) √ 主键ID NAME_ 部署名称 ...
- iscsi模型相关点
1.iscsi即ip scsi,按架构分为控制器架构.链接桥系统架构.pc系统架构.这里主要说明一下pc系统架构. 所谓的pc系统架构,就是利用target软件存储端+initiator客户端+tcp ...
- 树上战争(HDU 2545 并查集求解点到根节点长度)
树上战争 Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- QTableView使用HTML显示富文本
对于QTableView中的显示,我们前面介绍过很多种,其中包括:文本.进度条.复选框等,今天我们介绍一下关于富文本的显示. 可能绝大多数小伙伴会通过QAbstractTableModel中的data ...