CoreAnimation-07-CAAnimationGroup
概述
- 简介
- CAAnimationGroup又称组动画或动画组
- 将多个动画放到动画组中,并赋值给layer的animations属性,动画组中所有动画就会并发执行
- 注意事项
- 动画组中的动画不会被压缩,超出动画时长的部分将会被剪掉
- 动画组中的动画的delegate与removedOnCompletion属性将会被忽略
- 由于忽略了removedOnCompletion属性,动画结束layer会恢复到动画前的状态
CAAnimationGroup唯一的属性
- animations(NSArray<CAAnimation *> *)
- 存放并发执行的所有动画
- 数组元素为CAAnimation的子类
示例
效果图

实现思路
- 创建动画组对象group
- 创建多个CABasicAnimation对象,分别作用与不通过的属性
- 将多个基本动画对象赋值给group的animations属性
- 将动画组添加到要执行动画的图层上
- 通过隐式动画改变图层的背景颜色
实现步骤
- 通过storyboard创建UIView控件,并拥有它,修改它的class属性为自定义的UIView的子类
@property (weak, nonatomic) IBOutlet UIView *redView;
- 创建动画组
//创建动画组对象
CAAnimationGroup *group = [CAAnimationGroup animation];
//设置动画组的执行时间
group.duration = 1.0; //创建基本动画对象,用来进行缩放
CABasicAnimation *scale = [CABasicAnimation animation];
scale.keyPath = @"transform.scale";
scale.fromValue = @1.0;
scale.toValue = @0.5; //创建基本动画对象,用来进行旋转
CABasicAnimation *rotation = [CABasicAnimation animation];
rotation.keyPath = @"transform.rotation";
rotation.toValue = @(arc4random_uniform(M_PI * 2)); //创建基本动画对象,用来修改位置
CABasicAnimation *position = [CABasicAnimation animation];
position.keyPath = @"position";
position.toValue = [NSValue valueWithCGPoint:CGPointMake(arc4random_uniform(200) + 20, arc4random_uniform(200) + 20)]; //将基本动画添加到动画组中
group.animations = @[scale, rotation, position];
- 将动画组添加到要执行动画的图层上
[self.redView.layer addAnimation:group forKey:nil];
- 通过隐式动画改变layer的背景色
self.redView.layer.backgroundColor = [self randomColor].CGColor;
- 实现返回随机颜色的方法
//返回随机颜色
- (UIColor *)randomColor
{
return [UIColor colorWithRed:arc4random_uniform(255) / 255.0 green:arc4random_uniform(255) / 255.0 blue:arc4random_uniform(255) / 255.0 alpha:1.0];
}
CoreAnimation-07-CAAnimationGroup的更多相关文章
- CoreAnimation confusion: CATransaction vs CATransition vs CAAnimationGroup?
http://stackoverflow.com/questions/14042755/coreanimation-confusion-catransaction-vs-catransition-vs ...
- iOS CoreAnimation详解(一) 有关Layer的动画
以前由于项目需要 也写了一些动画 ,但是知识不系统,很散.这段时间趁着项目完成的空袭,来跟着大神的脚步系统的总结一下iOS中Core Animation的知识点. 原博客地址:http://blog. ...
- iOS CoreAnimation 核心动画
一 介绍 一组非常强大的动画处理API 直接作用在CALAyer上,并非UIView(UIView动画) CoreAnimation是所有动画的父类,但是不能直接使用,应该使用其子类 属性: dura ...
- ios基础篇(二十五)—— Animation动画(UIView、CoreAnimation)
Animation主要分为两类: 1.UIView属性动画 2.CoreAnimation动画 一.UIView属性动画 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程.UIVie ...
- iOS关于CoreAnimation动画知识总结
一:UIKit动画 在介绍CoreAnimation动画前先简单介绍一下UIKit动画,大部分简单的动画都可以使用UIKit动画实现,如果想实现更复杂的效果,则需要使用Core Animation了: ...
- CoreAnimation方法汇总
使用CoreAnimation一般分为三个部分:1.创建执行动画的CALayer 2.创建动画 3.CALayer 添加Animation CoreAnimation是以锚点为基础. CoreAnim ...
- CoreAnimation笔记
核心动画继承结构 CoreAnimation Core Animation是直接作用在CALayer上的(并非UIView上)非常强大的跨Mac OS X和iOS平台的动画处理API,Core Ani ...
- 第二十九篇、CoreAnimation的使用
使用的的三个步骤 1.初始化演员 2.设置好剧情 3.播放 主要类: CALayer // 绘图部分 CABaseAnimation // 基本动画(缩放,移动) CAKeyframeAnimatio ...
- CoreAnimation
CoreAnimation 1.CABasicAnimation // position CABasicAnimation *ba = [CABasicAnimation animationWithK ...
- CoreAnimation (CALayer 动画)
CoreAnimation基本介绍: CoreAnimation动画位于iOS框架的Media层 CoreAnimation动画实现需要添加QuartzCore.Framework CoreAnima ...
随机推荐
- http协议客户端向服务器端请求时一般需要发送的内容
out.println("GET /shopping/index.html HTTP/1.1");//请求行 包括请求方式,文件路径, http协议版本(必写)请求头.... ou ...
- java中DatagramSocket连续发送多个数据报包时产生丢包现象解决方案
try { //向指定的ip和端口发送数据~! //先说明一下数据是谁发送过来的! byte[] ip = InetAddress.getLocalHost().getHostAddress().ge ...
- [Math] A love of late toward Mathematics - how to learn it?
Link: https://www.zhihu.com/question/19556658/answer/26950430 王小龙 ,数学,计算机视觉,图形图像处理 数学系博士怒答! 我想大家 ...
- android 代码控制控件的长宽,小技巧
要在代码里改变ImageView 的长宽,如图 通过拿到contentImage这对象的控件参数,再去改变,再设置 , 上图的contentImage为ImageView对象: 而这里 要提醒的是,L ...
- tar的-t参数使用
-t, --list list the contents of an archive 例如: pengdl@localhost:~/test$ tar -czvf shell.ta ...
- "浅谈Android"第二篇:活动(Activity)
距离上一篇文章,过去有半个多月了,在此期间忙于工作,疏于整理和总结,特此写下这篇博文,来谈谈自己对Activity的理解.总所周知,Activity组件在Android中的重要性不言而喻,我们 ...
- 【团队冲刺总结】一个编码人员的反(tu)思(cao)
消失了半个多月了啊,算算时间,好像确实有近个把月没有好好的写博客来了.我一直很想写博客的,之前有老师问过写博客的动力是什么.我想了想,我觉得可能是我比较喜欢看书吧,不管是专业书还是小说(好吧,我承认, ...
- 用Qt写软件系列一:QCacheViewer(浏览器缓存查看器)
介绍 Cache技术广泛应用于计算机行业的软硬件领域.该技术既是人们对新技术探讨的结果,也是对当前软硬件计算能力的一种妥协.在浏览器中使用cache技术,可以大幅度提高web页面的响应速度,降低数据传 ...
- 常见的几种 CSS 水平垂直居中解决办法
用CSS实现元素的水平居中,比较简单,可以设置text-align center,或者设置 margin-left:auto; margin-right:auto 之类的即可. 主要麻烦的地方还是在垂 ...
- C#创建自定义配置节
在.Net应用程序中,我们经常看到VS为我们生成的项目工程中都会含有nfig或者nfig这样的文件.这个文件就是我们所说的应用程序配置文件.在这个文件里面记述着一些与我们的应用程序相关的信息,如:数据 ...