Core Animation中的组动画
实际开发中一个物体的运动往往是复合运动,单一属性的运动情况比较少,但恰恰属性动画每次进行动画设置时一次只能设置一个属性进行动画控制(不管是 基础动画还是关键帧动画都是如此),这样一来要做一个复合运动的动画就必须创建多个属性动画进行组合。对于一两种动画的组合或许处理起来还比较容易,但是 对于更多动画的组合控制往往会变得很麻烦,动画组的产生就是基于这样一种情况而产生的。动画组是一系列动画的组合,凡是添加到动画组中的动画都受控于动画 组,这样一来各类动画公共的行为就可以统一进行控制而不必单独设置,而且放到动画组中的各个动画可以并发执行,共同构建出复杂的动画效果。
动画组使用起来并不复杂,首先单独创建单个动画(可以是基础动画也可以是关键帧动画),然后将基础动画添加到动画组,最后将动画组添加到图层即可。
//
// 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中的组动画的更多相关文章
- Core Animation中的关键帧动画
键帧动画就是在动画控制过程中开发者指定主要的动画状态,至于各个状态间动画如何进行则由系统自动运算补充(每两个关键帧之间系统形成的动画称为“补间动画”),这种动画的好处就是开发者不用逐个控制每个动画帧, ...
- Core Animation中的基础动画
基础动画 在开发过程中很多情况下通过基础动画就可以满足开发需求,前面例子中使用的UIView代码块进行图像放大缩小的演示动画也是基础动画(在iOS7 中UIView也对关键帧动画进行了封装),只是UI ...
- 使用Core Animation对象来实现动画
转载保留原文地址:http://blog.csdn.net/kqjob/article/details/10417461,转载的 在iOS中如果使用普通的动画则可以使用UIKit提供的动画方式来实现, ...
- iOS Core Animation学习总结(3)--动画的基本类型
一. CABasicAnimation (基础动画) 移位: CABasicAnimation *animation = [CABasicAnimation animation]; //keyPath ...
- jQuery动画高级用法(上)——详解animation中的.queue()动画队列插队函数
决定对animate方面做一些总结,希望能给大家一些启发和帮助 从一个实际应用谈起 今天不谈animate().fadeIn().fadeOut().slideUp().show().hide()诸如 ...
- 在ios中运用core animation暂停和继续动画
本文转载至 http://blog.csdn.net/wildfireli/article/details/23191861 暂停和继续动画的核心代码如下: <pre name="co ...
- core Animation之CAKeyframeAnimation(关键帧动画)
CABasicAnimation的区别是:CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSA ...
- Core Animation之CABasicAnimation(基础动画)
#import "ViewController.h" @interface ViewController () @property(nonatomic,strong)UIButto ...
- IOS动画(Core Animation)总结 (参考多方文章)
一.简介 iOS 动画主要是指Core Animation框架.官方使用文档地址为:Core Animation Guide. Core Animation是IOS和OS X平台上负责图形渲染与动画的 ...
随机推荐
- erase-credentials配置
转自:Spring Security怎样不让默认的ProviderManager清除密码等信息 <authentication-manager erase-credentials="f ...
- C++ static与单例模式
单例模式是应用最多的一种设计模式,它要求系统中每个类有且只能有一个实例对象. 主要优点: 1.提供了对唯一实例的受控访问. 2.由于在系统内存中只存在一个对象,因此可以节约系统资源,对于一些需要频繁创 ...
- div套div 里面div有浮动 外面div自适应高度
<div style="background-color:red;"> <div style="float:left;background-color: ...
- Dynamic Programming - leetcode [动态规划]
115. Distinct Subsequences 96. Unique Binary Search Trees 120. Triangle 123. Best Time to Buy and Se ...
- Android服务
开启服务 (startservice) 服务一旦开启与调用者没有任何的关系 , 调用着的activity 即便是退出了 也不会影响 后台的service的运行. 在activity里面 不能去调用服务 ...
- Zsh安装
Zsh 使用 Homebrew 完成 zsh 和 zsh completions 的安装 brew install zsh zsh-completions 安装 oh-my-zsh 让 zsh 获得拓 ...
- crontab记录
简单说一下分类: 1.系统定时路径在/etc/crontab,直接进行编辑即可,这里注意,设定执行时间之后,第二个要跟用户名 ,例如: 1 * * * * root run-parts /etc/cr ...
- HDU 3294 Girls' research
题目地址 manacher #include<cstdio> #include<string.h> #include<algorithm> using namesp ...
- Documention
Object.bool Does the object exist? Object.name Components share the same name with the game object a ...
- mybatis配置sql超时时间
mybatis如果不配置,默认超时时间是不做限制的.当系统慢sql很多时,势必会增加数据库压力,系统性能及稳定性降低.所以有必要要设置sql超时设置,下面配置超时时间是5分钟. 第一步:全局配置如下 ...