Method
+ (void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion
+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion
+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations
duration:持续时间
delay:延迟时间
options:选项,详细看下表
animations:动画block
completion:完成block
Animatable properties
Position and size | Appearance | Transformation | |
---|---|---|---|
bounds | backgroundColor | transform | |
frame | alpha | ||
center |
Springs
+ (void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
usingSpringWithDamping:(CGFloat)dampingRatio
initialSpringVelocity:(CGFloat)velocity
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion
Spring.gifdampingRatio:阻尼系数(0~1)
velocity:初始速度
Transitions
+ (void)transitionWithView:(UIView *)view
duration:(NSTimeInterval)duration
options:(UIViewAnimationOptions)options
animations:(void (^ __nullable)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion
+ (void)transitionFromView:(UIView *)fromView
toView:(UIView *)toView
duration:(NSTimeInterval)duration
options:(UIViewAnimationOptions)options
completion:(void (^ __nullable)(BOOL finished))completion
// toView added to fromView.superview, fromView removed from its superview
Transitions.gif
UIViewAnimationOptions
UIViewAnimationOptionLayoutSubviews 动画过程中保证子视图跟随运动
UIViewAnimationOptionAllowUserInteraction 允许交互
UIViewAnimationOptionBeginFromCurrentState 从当前状态开始运行
UIViewAnimationOptionRepeat 重复
UIViewAnimationOptionAutoreverse 逆动画
UIViewAnimationOptionOverrideInheritedDuration 忽略嵌套动画时间设置
UIViewAnimationOptionOverrideInheritedCurve 忽略嵌套动画速度设置
UIViewAnimationOptionAllowAnimatedContent 动画过程中重绘视图(仅适用转场)
UIViewAnimationOptionShowHideTransitionViews 转场隐藏旧视图
UIViewAnimationOptionOverrideInheritedOptions 不继承父动画设置
UIViewAnimationOptionCurveEaseInOut 先慢后快再慢
UIViewAnimationOptionCurveEaseIn 逐渐变慢
UIViewAnimationOptionCurveEaseOut 逐渐变快
UIViewAnimationOptionCurveLinear 线性运动
UIViewAnimationOptionTransitionNone 无效果
UIViewAnimationOptionTransitionFlipFromLeft 绕X轴逆时针旋转
UIViewAnimationOptionTransitionFlipFromRight 绕X轴顺时针旋转
UIViewAnimationOptionTransitionCurlUp 从右下角掀起
UIViewAnimationOptionTransitionCurlDown 从右下角落下
UIViewAnimationOptionTransitionCrossDissolve 溶解
UIViewAnimationOptionTransitionFlipFromTop 从上方翻转
UIViewAnimationOptionTransitionFlipFromBottom 从下方翻转
options.gif
Keyframe Animations
+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
options:(UIViewKeyframeAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion
+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTime
relativeDuration:(double)frameDuration
animations:(void (^)(void))animations
frameStartTime:起始时间点(0~1)
frameDuration:持续时间(0~1)
Demo
[UIView animateKeyframesWithDuration:5.0f
delay:0.0f
options:UIViewKeyframeAnimationOptionCalculationModeLinear
animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0f
relativeDuration:0.3f
animations:^{
_testView.y += 100;
}];
[UIView addKeyframeWithRelativeStartTime:0.3f
relativeDuration:0.7f
animations:^{
_testView.x += 50;
}];
}
completion:nil];
UIViewKeyframeAnimationOptions
UIViewKeyframeAnimationOptionLayoutSubviews
UIViewKeyframeAnimationOptionAllowUserInteraction
UIViewKeyframeAnimationOptionBeginFromCurrentState
UIViewKeyframeAnimationOptionRepeat
UIViewKeyframeAnimationOptionAutoreverse
UIViewKeyframeAnimationOptionOverrideInheritedDurationnested
UIViewKeyframeAnimationOptionOverrideInheritedOptions
UIViewKeyframeAnimationOptionCalculationModeLinear 连续运行模式
UIViewKeyframeAnimationOptionCalculationModeDiscrete 离散运行模式
UIViewKeyframeAnimationOptionCalculationModePaced 均匀执行运行模式
UIViewKeyframeAnimationOptionCalculationModeCubic 平滑运行模式
UIViewKeyframeAnimationOptionCalculationModeCubicPaced 平滑均匀运行模式
UIViewKeyframeAnimationOptions.gif
网友评论