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

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

//
// 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. Spring Security(16)——基于表达式的权限控制

    目录 1.1      通过表达式控制URL权限 1.2      通过表达式控制方法权限 1.2.1     使用@PreAuthorize和@PostAuthorize进行访问控制 1.2.2   ...

  2. Oracle新建实例后,修改sys和system密码。

    sqlplus/nolog connect sys as sysdba alert user sys identified by pwd;

  3. ECOS-Mongodb安装

    安装Mongodb服务 安装Mongodb服务 author :James,jimingsong@vip.qq.com since :2015-03-03 下载Mongodb安装包(64位哦) 安装M ...

  4. web端和手机端测试有什么不同

    面试中经常被问到web端测试和手机端测试有什么相同点和区别呢?现在总结一下这个问题,如有不对敬请指正 web端和手机端测试有什么区别 1.相同点 不管是web测试还是手机App测试,都离不开测试的相关 ...

  5. 用sql实现汉字转拼音

    有时我们会需要将汉字转为拼音,例如需要将省市转为拼音后当做编码存储(尽管国家有统一的标识码,但有时候我们还是会用到),网络上也有工具提供汉字转拼音的功能,但各有优劣,一般转拼音后还会存在带声调的字母, ...

  6. FD.io VPP 技术Neutron VNF vRouter 实现

    在OpenStack Neutron中主要有三种网络设备,路由器(Router),负载均衡器(LB)以及VPN,其中Router作为基础网络设备起到连接子网到子网.内网到外网的作用.不同子网之间的访问 ...

  7. PHP 分析1

    D:\wamp64\www\practice test 3: PHP 显示乱码 http://localhost/practice/ex1_5_stu.php <html><meta ...

  8. react学习笔记-05 lifecycle

    根据React官网,react有三个生命状态:装载(Mounting),更新(updating),卸载() 一:装载 装载:componentWillMount/componentDidMount(组 ...

  9. Yii2 基于RESTful架构的 advanced版API接口开发 配置、实现、测试【转】

    环境配置: 开启服务器伪静态 本处以apache为例,查看apache的conf目录下httpd.conf,找到下面的代码 LoadModule rewrite_module modules/mod_ ...

  10. mac版tomcat修改端口无法访问,80端口无法访问

    在mac上安装好了tomcat,修改了端口为80,没想到关闭tomcat时提示出错,而且无法访问,原来我犯了两个错误. 1.我用的是mac上的文本编辑.app打开然后修改的,重新修改为8080也不行, ...