iOS有三种动画.
1.头尾式动画(不重要)
基本上这些动画都是调用的UIView的方法.
[UIView beginAnimations:nil context:nil];//准备开始动画
[UIView setAnimationDuration:5];//设置时间
[UIView commitAnimations];//提交动画(真正开始做动画)
alpha = 0; // 透明度 取值范围 0 - 1(之前的设置RGB色里面有讲到)
*注意:系统的默认动画时间是 0.2/0.25 秒
2.块动画
+(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^__nullable)(BOOL finished))completion;
+(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;
+(void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)optionsanimations:(void (^)(void))animations completion:(void (^__nullable)(BOOL finished))completion;
参数解释:
duration : 动画时间
delay : 延迟时间
dampingRatio : 阻尼系数(弹性) 越小越弹
velocity : 速率
options : 选项
animations : 做动画的代码块
completion : 动画完成的代码块 "回调"
3.序列帧动画
方法1
-[UIImage animatedImageWithImages:动画数组 duration:持续时间]; // 可以获取一个能做动画的UIImage对象
方法2
self.imageView.animationImages = array; // 装图片的数组(需要做动画的图片数组)
self.imageView.animationDuration = 2; // 动画时间
self.imageView.animationRepeatCount = 1; // 重复次数 0 表示重复
[self.imageView startAnimating]; // 开始序列帧动画
第一种基本上都不怎么用.一般第二种用的最多了.