其实早在一个多月以前就已经实现了动作组播放的功能,不过当时感觉好像没有什么难度并没有放在心上,今天突然要用到动画组,发现已经忘记了,所以又将原来的代码翻出来看了下。最后决定还是写下来,以备不时之需。动画组播放很简单,使用的是CAAnimationGroup这个类,将不同的动画添加到里面进行播放。通常可以添加的动画有:1、keyPath,它用来绘制路径,直线或者曲线,从理论上讲任意的线都可以绘制;2、旋转动画,它可以绕x、y、z轴进行旋转;3、缩放动画。

  废话不多说,直接上代码。

  

 #define pathAnimation @"position"
#define transformX @"transform.rotation.x"
#define transformY @"transform.rotation.y"
#define transformZ @"transform.rotation.z"
#define scaleAnimation @"position scale"
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h> //NSString *const pathAnimation = @"position"; //运动轨迹
//NSString *const transformX = @"transform.rotation.x"; //绕x轴旋转
//NSString *const transformY = @"transform.rotation.y"; //绕y轴旋转
//NSString *const transformZ = @"transform.rotation.z"; //绕z轴旋转
//NSString *const scaleAnimation = @"position scale"; //缩放 typedef enum AnimationType{
KeyPathAnimation, //运动轨迹为抛物线
RotationAnimationX, //绕x轴旋转
RotationAnimationY, //绕y轴旋转
RotationAnimationZ, //绕z轴旋转
ScaleAnimation //缩放
}AnimationType; @protocol LMFThowingLineToolDelegate <NSObject> - (void)animationDidFinish; @end @interface LMFThowingLineTool : NSObject
@property (nonatomic, strong) NSMutableArray *typeArray;//用来存储动画类型
@property (nonatomic, strong) NSArray *pointArray;
@property (nonatomic, strong) CAKeyframeAnimation *keyFrameAnimation;
@property (nonatomic, strong) CABasicAnimation *basicAnimation;
@property (nonatomic, strong) UIView *showView;
@property (nonatomic, assign) CGFloat duration;
@property (nonatomic, assign) id<LMFThowingLineToolDelegate> delegate;
- (void)setPointArray:(NSArray *)pointArray;
- (void)setDuration:(CGFloat)duration;
- (void)setKeyFrameAnimation;
- (void)setBasicAnimationWith:(AnimationType)animationType;
- (void)thowingView:(UIView *)view;
- (void)setTransform:(CGFloat)angle and:(AnimationType)animationType;
@end

  实现类:

 

 #import "LMFThowingLineTool.h"
#import "LMFPoint.h" @interface LMFThowingLineTool () @end @implementation LMFThowingLineTool - (void)dealloc
{
self.basicAnimation = nil;
self.keyFrameAnimation = nil;
NSLog(@"%@", self.basicAnimation);
} - (instancetype)init
{
if (self = [super init])
{
self.typeArray = [NSMutableArray array];
}
return self;
}
- (void)setPointArray:(NSArray *)pointArray
{
_pointArray = pointArray;
}
- (void)setDuration:(CGFloat)duration
{
_duration = duration;
}
- (void)setKeyFrameAnimation
{
if ([self.pointArray count] == )
{
return;
}
CGMutablePathRef path = CGPathCreateMutable(); if ([self.pointArray count] == )
{
LMFPoint * startPoint = (LMFPoint *)self.pointArray[];
LMFPoint * centerPoint = (LMFPoint *)self.pointArray[];
LMFPoint * endPoint = (LMFPoint *)self.pointArray[];
CGPathMoveToPoint(path, NULL, startPoint.x, startPoint.y);
//这里用的直线的路径,也可以设置抛物线,获取曲线,可进行自定义
CGPathAddQuadCurveToPoint(path, NULL, centerPoint.x, centerPoint.y, endPoint.x, endPoint.y);
}
else if ([self.pointArray count] > )
{
return;
}
self.keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:pathAnimation];
self.keyFrameAnimation.path = path;
CFRelease(path);
[self.typeArray addObject:self.keyFrameAnimation];
}
- (void)setTransform:(CGFloat)angle and:(AnimationType)animationType
{ }
- (void)setBasicAnimationWith:(AnimationType)animationType
{
self.basicAnimation = [[CABasicAnimation alloc] init];
self.basicAnimation.autoreverses = YES;
self.basicAnimation.repeatCount = MAXFLOAT;
self.basicAnimation.duration = self.duration;
switch (animationType) {
case RotationAnimationX:
self.basicAnimation.keyPath = transformX;
break;
case RotationAnimationY:
self.basicAnimation.keyPath = transformY;
break;
case RotationAnimationZ:
self.basicAnimation.keyPath = transformZ;
break;
case ScaleAnimation:
self.basicAnimation.keyPath = scaleAnimation;
self.basicAnimation.toValue = [NSNumber numberWithFloat:(CGFloat)((arc4random() % ) + ) / 10.0];
[self.typeArray addObject:self.basicAnimation];
break;
default:
break;
}
self.basicAnimation.fromValue = [NSNumber numberWithFloat:0.0];
int intNumber = arc4random()%+;
self.basicAnimation.toValue = [NSNumber numberWithFloat:intNumber*M_PI];
[self.typeArray addObject:self.basicAnimation];
} #pragma mark --开始执行动画
- (void)thowingView:(UIView *)view
{
self.showView = view;
CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
// groupAnimation.delegate = self;
groupAnimation.repeatCount = ;
groupAnimation.duration = self.duration;
groupAnimation.removedOnCompletion = NO;
groupAnimation.animations = self.typeArray;
[view.layer addAnimation:groupAnimation forKey:@"position scale"];
} - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
[self.showView removeFromSuperview];
self.showView = nil;
} @end

  额外需要的类:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h> @interface LMFPoint : NSObject
@property (nonatomic, assign) CGFloat x;
@property (nonatomic, assign) CGFloat y;
- (instancetype)initWith:(CGFloat)x and:(CGFloat)y;
@end #import "LMFPoint.h" @implementation LMFPoint
- (instancetype)initWith:(CGFloat)x and:(CGFloat)y
{
if (self = [super init])
{
self.x = x;
self.y = y;
}
return self;
} - (NSString *)description
{
return [NSString stringWithFormat:@"x:%f y:%f", self.x, self.y];
} @end

iOS 动画组的更多相关文章

  1. ios基础动画、关键帧动画、动画组、转场动画等

    概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌.在这里你可以看到iOS中如何使用图层精简非交互式绘图,如何通过核心动画创建基础动画.关键帧动画 ...

  2. IOS第18天(9,核心动画-动画组)

    ****动画组 // 核心动画都是假象,不能改变layer的真实属性的值// 展示的位置和实际的位置不同.实际位置永远在最开始位置 #import "HMViewController.h&q ...

  3. iOS:核心动画之动画组CAAnimationGroup

    CAAnimationGroup——动画组 动画组,是CAAnimation的子类,可以保存一组动画对象,将CAAnimationGroup对象加入层后,组中所有动画对象可以同时并发运行 属性说明: ...

  4. IOS-用动画组制作花瓣掉落效果(另附iOS动画图表)

    重要的两个方法:1.动画的数组:animations 2.启动的时间 beginTime 注意:动画组设置了持续时间(duration)可能会导致动画组里面的持续时间不管用 代码如下: #import ...

  5. IOS开发核心动画六:动画组

    #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutl ...

  6. iOS动画实现总结

    在iOS中,动画实现方向有两种,一种是操作UIView的animation方法,另外一种就是核心动画,但到iOS7中,UIView又跟核心动画牵扯在一起. 方式一(利用核心动画添加动画) 核心动画的层 ...

  7. IOS 动画专题 --iOS核心动画

    iOS开发系列--让你的应用“动”起来 --iOS核心动画 概览 通过核心动画创建基础动画.关键帧动画.动画组.转场动画,如何通过UIView的装饰方法对这些动画操作进行简化等.在今天的文章里您可以看 ...

  8. iOS 动画篇 之 Core Animation (一)

    iOS中实现动画有两种方式,一种是自己不断的通过drawRect:方法来绘制,另外一种就是使用核心动画(Core Animation). 导语: 核心动画提供高帧速率和流畅的动画,而不会增加CPU的负 ...

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

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

随机推荐

  1. Classic Shell 4.2.4 中文版已经发布

    新版本支持 windows 10 操作系统了.请点击本博客页面左上角的链接下载. 博主的电脑最近也升级到 Windows 10 操作系统,用了没几天就出现打不开“开始”菜单.Edge.计算器等 App ...

  2. https基础流程

    背景: https基于SSL,目的是保护http通信的过程,防止中间人篡改信息,或假冒服务端的问题.   要解决的问题: 1. 客户端如何证明是与正确的服务端进行通信 2. 客户端如何确认收到服务端的 ...

  3. ThinkPHP 下如何隐藏index.php

    最近一直在做孕妈团的项目,因为部署到实际项目中出现了链接打不开的情况,要默认添加index.php才能正常访问. 当时忘了是Tinkphp的URL重写模式:以后遇到相同问题,首先要想到URL重写模式. ...

  4. YbSoftwareFactory 代码生成插件【二十四】:MVC中实现动态自定义路由

    上一篇介绍了 公文流转系统 的实现,本篇介绍下MVC下动态自定义路由的实现. 在典型的CMS系统中,通常需要为某个栏目指定个友链地址,通过指定友链地址,该栏目的地址更人性化.方便记忆,也有利用于搜索引 ...

  5. java equals和==的区别

    大概说equals和==都比较的是什么: 1. boolean tem = a == b; 首先==比较的肯定是地址,从堆栈的角度说也就是说==比较的是栈上面的内容.因为栈是用来存放地址或是java中 ...

  6. jsp九大内置对象、四种作用域、跳转方式

    jsp有四种属性范围: page -> 页面级别,显然只有在一个页面内可用. request -> 请求级别 服务器跳转,一次请求之后消失. session -> 会话级别 客户端跳 ...

  7. log4j日志配置

    #debug#日志权限配置log4j.rootLogger=info,error,stdout#控制台输出log4j.appender.stdout=org.apache.log4j.ConsoleA ...

  8. App瘦身

    http://www.zoomfeng.com/blog/ipa-size-thin.html https://github.com/ming1016/SMCheckProject

  9. ImageList图标左边有黑色竖线

    ImageList图标左边有黑色竖线, 原因 ImageList颜色深度太小引起的,解决方案,把颜色深度调成Depth32Bit 默认: 修改为: 结果: 备注:根据文件获得文件的系统图标: Icon ...

  10. DateEdit控件的使用

    按照年月日时分秒显示时间 1. 设置Mask.EditMask和DisplayFormat,EditFormat属性,设置为一致:'yyyy-MM-dd HH:mm';  //按照想要的显示格式设置此 ...