本讲内容
一、动画的使用场景
二、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;
|
增加⼀一个动画设置参数 |
UIViewTransition的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;
|
三、CGAffineTransform2D仿射变换
CGAffineTransform的使⽤
CGAffineTransform是结构体,表⽰一个矩阵,⽤于映射视图变换。
缩放、旋转、偏移是仿射变换⽀支持的最常⽤的操作。
缩放、缩放、偏移区分“基于上一次”和“基于初始”。
CGAffineTransfrom的API
四、CALayer
UIView和CALayer的区别和联系
UIView和CALayer的区别和联系
UIView
UIView和CALayer的区别和联系
Layer
UIView和CALayer的区别和联系
属性 作⽤用 | |
CornerRadius |
圆⾓角 |
ShadowColor |
阴影颜⾊色 |
ShadowOffset |
阴影偏移距离 |
ShadowRadius |
阴影模糊程度 |
ShadowOpacity |
阴影透明度 |
BorderWidth |
描边粗细 |
BorderColor |
描边颜⾊色 |
anchorPoint |
锚点 |
positiontransfrom |
位置信息 |
使CALayer产⽣生3D空间内的平移、缩放、旋转等变化 |
anchorPoint和position
anchorPoint和position
anchorPoint和position
anchorPoint和position
anchorPoint和position
五、CAAnimation动画
!
CAAnimationCAAnimation是抽象类,通常使⽤用它的⼦类实现动画效果
所有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相关子类CAAnimationGroup
CAAnimation
CAPropertyAnimation
CABasicAnimation
KeyFrameAnimation
CATransition
CAPropertyAnimationCAPropertyAnimation也是⼀个抽象类
通常我们都使⽤它的两个子类:CABasicAnimation和CAKeyFrameAnimation
CABasicAnimation作⽤用:基本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(设置过渡动画的方向)
总结
一、动画的使用场景
二、UIView动画
三、CGAffineTransform2D仿射变换
四、CALayer
五、CAAnimation动画
MVC、通知