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 ...
随机推荐
- hdu1020Encoding
Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following ...
- No1_2. 流程控制_java学习笔记
import java.util.Scanner; import java.lang.Math; public class HelloForWhile { /** * 文档注释,程序名称:HelloF ...
- juqery合成事件toggle方法
当指定元素被点击时,在两个或多个函数之间轮流切换. 如果规定了两个以上的函数,则 toggle() 方法将切换所有函数.例如,如果存在三个函数,则第一次点击将调用第一个函数,第二次点击调用第二个函数, ...
- TRIGGERS_监测系统_原始数据表触发器—调用告警信息存储过程
//每次向originaldata表中插入数据就会触发该触发器 create or replace trigger originaldata_to_alarm after insert on ori ...
- 处理PHP中字符串的常用操作及函数
1. 确定一个字符串的长度 这是最为常见和基础的例子,对于确定一个字符串的长度,我们应该使用strlen()函数,比如要获取下面字符串$text 的长度: $text = "sunny da ...
- DOT + graphviz 轻松画图
一.简介DOT & graphviz1. DOT DOT是一种文本图形描述语言.DOT语言文件通常具有.gv或是.dot的文件扩展名.当然,在编写好.dot或者.gv的文件之后,需要有专 ...
- python笔记之提取网页中的超链接
python笔记之提取网页中的超链接 对于提取网页中的超链接,先把网页内容读取出来,然后用beautifulsoup来解析是比较方便的.但是我发现一个问题,如果直接提取a标签的href,就会包含jav ...
- python的时间模块
python有两个重要的时间模块,分别是time和datetime 先看time模块 表示时间的几种方法: 1)时间元组:time.struct_time(tm_year=2016, tm_mon ...
- 用Python设计第一个游戏 - 零基础入门学习Python002
用Python设计第一个游戏 让编程改变世界 Change the world by program 有些鱼油可能会说,哇,小甲鱼你开玩笑呐!这这这这就上游戏啦?你不打算给我们讲讲变量,分支,循环,条 ...
- 关于STM32工程的错误,狗血错误。。。..\CMSIS\core_cm3.h(1087): error: #20: identifier "IRQn_Type" is undefined
这件事还是要写一篇博客了,为了后来的人不换致命性的错误 辛辛苦苦写的一个四个不同的引脚不同时钟不同寄存器分别产生四种不同占空比不同周期的信号方波程序超级经典 PS:页尾上传PWM波形产生工程附件供大 ...