第⼆⼗三讲:动画


本讲内容

一、动画的使用场景

二、UIView动画

三、CGAffineTransform2D仿射变换

四、CALayer

五、CAAnimation动画


一、动画的使⽤用场景

iOS中的动画

iOS中的动画是指一些视图上的过渡效果合理利⽤动画能提高用户体验


动画的分类

二、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;

动画从当前状态继续执⾏行


UIView动画的实现


UIView动画块的用法


UIViewBlock动画的用法[UIView animateWithDuration:1.0 animations:^{!

 //在块语法中设置各种动画属性}];

//语句结束之后⾃动执行动画


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;

增加⼀一个动画设置参数


UIViewTransitionAPI

⽅法名

+ (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;

三、CGAffineTransform2D仿射变换


CGAffineTransform的使⽤

CGAffineTransform是结构体,表⽰一个矩阵,⽤于映射视图变换。

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

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



CGAffineTransfromAPI


四、CALayer


UIViewCALayer的区别和联系

UIViewCALayer的区别和联系


UIViewCALayer的区别和联系


UIView


UIViewCALayer的区别和联系

Layer


UIViewCALayer的区别和联系



CALayer的常⽤用属性

属性 作⽤用

CornerRadius

圆⾓角

ShadowColor

阴影颜⾊色

ShadowOffset

阴影偏移距离

ShadowRadius

阴影模糊程度

ShadowOpacity

阴影透明度

BorderWidth

描边粗细

BorderColor

描边颜⾊色

anchorPoint

锚点

positiontransfrom

位置信息

使CALayer产⽣生3D空间内的平移、缩放、旋转等变化


anchorPointposition


anchorPointposition



anchorPointposition



anchorPointposition



anchorPointposition



五、CAAnimation动画


!

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

所有CAAnimation及其⼦类的对象都添加在Viewlayer,例如:[view.layer addAnimation:animation forKey:nil];


layer添加/移除CALayer动画

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

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

CAAnimation相关子类CAAnimationGroup


CAAnimation

CAPropertyAnimation

CABasicAnimation

KeyFrameAnimation


CATransition


CAPropertyAnimationCAPropertyAnimation也是⼀个抽象类

通常我们都使⽤它的两个子类:CABasicAnimationCAKeyFrameAnimation



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


⽅方法名/属性名 作⽤用

+ (id)animationWithKeyPath:(NSString *)path;

系统提供的构造器⽅方法

@property(copy) NSString *keyPath;

只能填写CALayer中能够做动画的属性名

@property(retain) id fromValue;

起始值

@property(retain) id toValue;

结束值

@property(retain) id byValue;

相对值


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


⽅方法名/属性名 作⽤用

+ (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(设置过渡动画的方向)



总结

一、动画的使用场景

二、UIView动画

三、CGAffineTransform2D仿射变换

四、CALayer

五、CAAnimation动画



MVC、通知 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值