实际开发中一个物体的运动往往是复合运动,单一属性的运动情况比较少,但恰恰属性动画每次进行动画设置时一次只能设置一个属性进行动画控制(不管是 基础动画还是关键帧动画都是如此),这样一来要做一个复合运动的动画就必须创建多个属性动画进行组合。对于一两种动画的组合或许处理起来还比较容易,但是 对于更多动画的组合控制往往会变得很麻烦,动画组的产生就是基于这样一种情况而产生的。动画组是一系列动画的组合,凡是添加到动画组中的动画都受控于动画 组,这样一来各类动画公共的行为就可以统一进行控制而不必单独设置,而且放到动画组中的各个动画可以并发执行,共同构建出复杂的动画效果。

动画组使用起来并不复杂,首先单独创建单个动画(可以是基础动画也可以是关键帧动画),然后将基础动画添加到动画组,最后将动画组添加到图层即可。

//
// ViewController.m
// Demo02183
//
// Created by wiseman on 16/2/18.
// Copyright (c) 2016年 wiseman. All rights reserved.
// #import "ViewController.h" @interface ViewController ()
{
CALayer *_layer;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//自定义一个图层
_layer=[[CALayer alloc]init];
_layer.bounds=CGRectMake(, , , );
_layer.position=CGPointMake(, );
_layer.backgroundColor = [UIColor redColor].CGColor;
[self.view.layer addSublayer:_layer]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self groupAnimation];
} #pragma mark - 组动画
-(void)groupAnimation{
//1.创建动画组
CAAnimationGroup *animationGroup=[CAAnimationGroup animation]; //2.设置组中的动画和其他属性
CABasicAnimation *basicAnimation=[self rotationAnimation];
CAKeyframeAnimation *keyframeAnimation=[self translationAnimation];
animationGroup.animations=@[basicAnimation,keyframeAnimation]; animationGroup.delegate=self;
animationGroup.duration=10.0;//设置动画时间,如果动画组中动画已经设置过动画属性则不再生效
animationGroup.beginTime=CACurrentMediaTime();//延迟五秒执行 //3.给图层添加动画
[_layer addAnimation:animationGroup forKey:nil];
} #pragma mark - 基础旋转动画
-(CABasicAnimation *)rotationAnimation{
//1.创建基本动画
CABasicAnimation *basicAnima = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; //2.
CGFloat toValue = M_PI_2 * ;
basicAnima.toValue = [NSNumber numberWithFloat:toValue];
basicAnima.autoreverses = true;
basicAnima.repeatCount = HUGE_VALF;
basicAnima.removedOnCompletion = YES; return basicAnima;
} #pragma mark - 关键帧移动动画
-(CAKeyframeAnimation *)translationAnimation{
CAKeyframeAnimation *keyframeAnima = [CAKeyframeAnimation animationWithKeyPath:@"position"];
UIBezierPath *bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint:CGPointMake(, )];
[bezierPath addCurveToPoint:CGPointMake(, ) controlPoint1:CGPointMake(, ) controlPoint2:CGPointMake(, )]; keyframeAnima.path = bezierPath.CGPath; return keyframeAnima;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

Core Animation中的组动画的更多相关文章

  1. Core Animation中的关键帧动画

    键帧动画就是在动画控制过程中开发者指定主要的动画状态,至于各个状态间动画如何进行则由系统自动运算补充(每两个关键帧之间系统形成的动画称为“补间动画”),这种动画的好处就是开发者不用逐个控制每个动画帧, ...

  2. Core Animation中的基础动画

    基础动画 在开发过程中很多情况下通过基础动画就可以满足开发需求,前面例子中使用的UIView代码块进行图像放大缩小的演示动画也是基础动画(在iOS7 中UIView也对关键帧动画进行了封装),只是UI ...

  3. 使用Core Animation对象来实现动画

    转载保留原文地址:http://blog.csdn.net/kqjob/article/details/10417461,转载的 在iOS中如果使用普通的动画则可以使用UIKit提供的动画方式来实现, ...

  4. iOS Core Animation学习总结(3)--动画的基本类型

    一. CABasicAnimation (基础动画) 移位: CABasicAnimation *animation = [CABasicAnimation animation]; //keyPath ...

  5. jQuery动画高级用法(上)——详解animation中的.queue()动画队列插队函数

    决定对animate方面做一些总结,希望能给大家一些启发和帮助 从一个实际应用谈起 今天不谈animate().fadeIn().fadeOut().slideUp().show().hide()诸如 ...

  6. 在ios中运用core animation暂停和继续动画

    本文转载至 http://blog.csdn.net/wildfireli/article/details/23191861 暂停和继续动画的核心代码如下: <pre name="co ...

  7. core Animation之CAKeyframeAnimation(关键帧动画)

    CABasicAnimation的区别是:CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSA ...

  8. Core Animation之CABasicAnimation(基础动画)

    #import "ViewController.h" @interface ViewController () @property(nonatomic,strong)UIButto ...

  9. IOS动画(Core Animation)总结 (参考多方文章)

    一.简介 iOS 动画主要是指Core Animation框架.官方使用文档地址为:Core Animation Guide. Core Animation是IOS和OS X平台上负责图形渲染与动画的 ...

随机推荐

  1. 花点时间搞清top、clientTop、scrollTop、offsetTop

    [转贴]花点时间搞清top.clientTop.scrollTop.offsetTop   scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对象左边界和窗口中目前 ...

  2. validate验证

    导入需要的js          自动验证 <script src="${ctx }/static/assets/js/jquery-2.1.4.min.js">< ...

  3. Registry Workshop(注册表编辑器) V4.6.3 官方中文版

    软件名称: Registry Workshop(注册表编辑器)软件语言: 简体中文授权方式: 免费试用运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 1.1MB图 ...

  4. linux awk命令详解2

    awk是行处理器: 相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的问题,通常用来格式化文本信息 awk处理过程: 依次对每一行进行处理,然后输出 awk命令形式: awk [-F ...

  5. nodejs 实现简单的文件上传功能

    首先需要大家看一下目录结构,然后开始一点开始我们的小demo. 文件上传总计分为三种方式: 1.通过flash,activeX等第三方插件实现文件上传功能. 2.通过html的form标签实现文件上传 ...

  6. THML结构语义化之table/form

    以table/form标签语义化,做为博客首贴 应用场景1-table表格 <table> <caption> <thead> <th colspan=&qu ...

  7. 在iOS9中 xcode7 网络请求 如图片请求不显示等

    Application Transport Security has blocked a cleartext HTTP (http://) resource load since it is inse ...

  8. edgerouter bonding

    configure set interfaces bonding bond0 mode 802.3ad set interfaces ethernet eth1 bond-group bond0 se ...

  9. 用Karma和Jasmine测试Angular应用

    TEST: Before you've written any of the code, you know how you want it to behave. You have a specific ...

  10. Sublime的Package Control的安装

    最近在用Sublime,我想很多人和我一样都是先要安装PackageControl吧! 可是看了网上的好多博客感觉都太繁琐了 对于像我这样的小白来说实在有很多看不懂的地方 相对来说还是官网的那种方法更 ...