您的位置:首页 > 移动开发 > IOS开发

ios中的动画

2015-04-13 21:21 113 查看
ios中的动画是指一些视图上的过渡效果,是为了增加用户的体验的。

分类:

CALayer 动画 uiview动画 (uiview的属性动画,uiviewTransition动画)

一. UIVIew动画

UIView动画影响的属性:frame,center,alpha,bounds,transform,backgroundColor ;

UIView动画的设置:

+ (void)setAnimationDuration:(NSTimeInterval)duration; 动画持续时间

+ (void)setAnimationDelay:(NSTimeInterval)delay; 动画开始前延时

+ (void)setAnimationCurve:(UIViewAnimationCurve)curve; 动画的速度曲线

+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses; 动画反转

+ (void)setAnimationRepeatCount:(float)repeatCount; 动画反转的次数

+ (void)setAnimationDelegate:(id)delegate; 设置动画的代理

+ (void)setAnimationWillStartSelector:(SEL)selector; 动画开始的代理⽅方法

+ (void)setAnimationDidStopSelector:(SEL)selector; 动画结束的代理⽅方法

+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState; 动画从当前状态继续执⾏行

动画的实现:

动画块,block

[UIView beginAnimations:nil context:nil];! ! //标记动画块开始

。。。。。。 //设置各种动画属性

[UIView commitAnimations];! ! ! ! ! ! //标记动画块结束

UIViewBlock动画的API

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void

(^)(void))animations; 最简单的UIViewBlock动画

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void

(^)(void))animations completion:(void (^)(BOOL finished))completion; 增加⼀一个延时参数

+ (void)animateWithDuration:(NSTimeInterval)duration delay:

(NSTimeInterval)delay options:(UIViewAnimationOptions)options

animations:(void (^)(void))animations completion:(void (^)(BOOL

finished))completion;

增加一个动画设置参数

UIViewTransform的API

(void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:

(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL

finished))completion;

+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:

(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)

(BOOL finished))completion;

二.CGA分fineTransform2D仿射变换

CGAffineTransform是结构体,表示一个矩阵,用于映射视图变

换。

缩放、旋转、偏移是仿射变换支持的最常用的操作。

缩放、缩放、偏移区分“基于上一次”和“基于初始”

CGAffineTransfrom的API

CGFloat d,CGFloat tx, CGFloat ty) 通过设置矩阵值进⾏行变换

CGAffineTransform CGAffineTransformMakeScale(CGFloat sx,

CGFloat sy) 放⼤大缩⼩小(基于初始)

CGAffineTransform CGAffineTransformMakeRotation(CGFloat

angle) 旋转(基于初始)

CGAffineTransform CGAffineTransformScale(CGAffineTransform

t,CGFloat sx, CGFloat sy) 放⼤大缩⼩小(基于前⼀一次变化)

CGAffineTransform

CGAffineTransformRotate(CGAffineTransform t,CGFloat angle) 旋转(基于前⼀一次变化)

三.CALayer

UIView和CALayer的区别和联系

CALayer负责绘制,提供

UIView 需要展⽰示的内容。不

能交互。是UIView的⼀一个readonly属性

UIView负责交

互,显⽰示CALayer

绘制的内容

CALayer 的重用属性:

CornerRadius 圆⾓角

ShadowColor 阴影颜⾊色

ShadowOffset 阴影偏移距离

ShadowRadius 阴影模糊程度

ShadowOpacity 阴影透明度

BorderWidth 描边粗细

BorderColor 描边颜⾊色

anchorPoint 锚点

position 位置信息

transfrom

使CALayer产⽣生3D空间内的平移、

缩放、旋转等变化

三.CAAnimation动画

CAAnimation是抽象类,通常使⽤用它的⼦子类实现动画效果

所有CAAnimation及其⼦子类的对象都添加在View的layer上,例如:

[view.layer addAnimation:animation forKey:nil];

给layer添加与移除CALayer动画

- (void)addAnimation:(CAAnimation *)anim forKey:(NSString *)key;

- (void)removeAnimationForKey:(NSString *)key;

- (void)removeAllAnimations;

CAAnimation相关子类

CAAnimation :1.CAAnimationGroup

2.CAPropertyAnimation ( CABasicAnimation, CAKeyFrameAnimation)

3.CATransition

CAPropertyAnimation 动画

CAPropertyAnimation也是一个抽象类

通常我们使用它的两个子类:CABasicAnimation和CAKeyFrameAnimation

CA BasicAnimation动画:

作⽤用:基本layer动画,通过设定初始和结束值执行动画

+ (id)animationWithKeyPath:(NSString *)path; 系统提供的构造器⽅方法

@property(copy) NSString *keyPath; 只能填写CALayer中能够做

动画的属性名

@property(retain) id fromValue; 起始值

@property(retain) id toValue; 结束值

@property(retain) id byValue; 相对值

CAKeyFrameAnimation

作用:关键帧动画,可以让你的view的layer按照预定轨迹做动画

+ (id)animationWithKeyPath:(NSString *)path; 系统提供的构造器⽅方法

@property CGPathRef path; 通过制定⼀一个⾃自⼰己定义的path来让某⼀一个物体按照

这个路径进⾏行动画

@property(copy) NSArray *values; ⼀一个数组,提供了⼀一组关键帧的值, 当使⽤用path的

时候 values的值⾃自动被忽略。

@property(copy) NSArray *keyTimes; ⼀一个数组,设置每⼀一帧的时间,其成员必须是

NSNumber。设置详情查看API。

@property(copy) NSString *rotationMode; 设定关键帧中间的值是如何计算

CAAnimaitionGroup

CAAnimationGroup只有⼀一个数组属性,可以添加多个

CAAnimation,一起执行

CATrasition

作用:layer的过渡动画

有两个主要属性:type(设置过渡动画的效果)和subType(设置过渡

动画的方向)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐