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 ...
随机推荐
- (转载)Linux 套接字编程中的 5 个隐患
在 4.2 BSD UNIX® 操作系统中首次引入,Sockets API 现在是任何操作系统的标准特性.事实上,很难找到一种不支持 Sockets API 的现代语言.该 API 相当简单,但新的开 ...
- Yii中 RBAC(基于角色的访问控制权限)表结构原理分析
这里有几个概念很重要,我简单用大白话说一下; 权限:就是指用户是否可以执行哪些操作. 如:小张可以发帖.回帖.浏览,小红只能回帖.浏览 角色:就是上面说的一组操作的集合. 如:高级会员有发帖.回帖.删 ...
- .NET指定程序集的位置
有两种方法用来指定程序集的位置: 使用 <codeBase> 元素. 使用 <probing> 元素. 还可以使用 .NET Framework 配置工具 (Mscorcfg. ...
- struts2重点——ModelDriven
一.属性驱动 在目标 Action 类中,通过 setXxx() 方法来接收请求参数. 二.模型驱动 1.ParametersInterceptor 拦截器工作原理 ParametersInterce ...
- LeetCode - 30. Substring with Concatenation of All Words
30. Substring with Concatenation of All Words Problem's Link --------------------------------------- ...
- P6 EPPM Installation and Configuration Guide 16 R1 April 2016
P6 EPPM Installation and Configuration Guide 16 R1 April 2016 Contents About Installing and ...
- Microsecond and Millisecond C# Timer[转]
文章转至:http://www.codeproject.com/Articles/98346/Microsecond-and-Millisecond-NET-Timer IntroductionAny ...
- Oracle备份表结构和数据
--创建一份表结构 create table BASE_GOODSPAYMENT_SETTING_BAK as select * from BASE_GOODSPAYMENT_SETTING ; -- ...
- Ajax,谷歌提示AutoCompleteExtender控件
提示内容从数据库中读取: ------------------------------------------页面 <asp:ScriptManager ID="ScriptManag ...
- jetty加载spring-context容器源码分析
带着疑问开始 web.xml的顺序问题 先拿一个最简单的spring mvc web.xml来说问题,如下图:如果我将三者的顺序倒置或是乱置,会产生什么结果呢? 启动报错?还是加载未知结果?还是毫无影 ...