一、+ (void)beginAnimations:(NSString *)animationID context:(void *)context; 开始一个动画
[UIView beginAnimations:@"go" context:nil];
4.0以后推荐使用+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
二、+ (void)commitAnimations; 结束动画, 类似数据库的事务处理
[UIVew commitAnimations];
三、+ (void)setAnimationDelegate:(id)delegate; 设置动画委托
[UIView setAnimationDelegate:self];
四、+ (void)setAnimationWillStartSelector:(SEL)selector; //当动画执行开始时,执行selector方法
[UIView setAnimationWillStartSelector:@selector(demo:)];
五、+ (void)setAnimationDidStopSelector:(SEL)selector; //当动画执行结束时,执行selector方法
[UIView setAnimationWillStartSelector:@selector(demo:)];
六、+ (void)setAnimationDuration:(NSTimeInterval)duration; //设置动画时间, 时间参数为double类型
[UIView setAnimationDuration:10.00];
七、+ (void)setAnimationDelay:(NSTimeInterval)delay; //设置动画延迟时间,单位秒
[UIView setAnimationDelay:10.00];
八、+ (void)setAnimationStartDate:(NSDate *)startDate; 设置在动画块内部动画属性改变的开始时间
NSTimeInterval secondsPerDay = 24*60*60;
NSDate *tomorrow = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];
[UIView setAnimationStartDate:tomorrow];
九、+ (void)setAnimationCurve:(UIViewAnimationCurve)curve; 设置动画的旋转曲度变化
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
值定义在UIViewAnimationCurve结构体中。
typedef NS_ENUM(NSInteger, UIViewAnimationCurve) { //动画曲线
UIViewAnimationCurveEaseInOut, // slow at beginning and end 缓慢开始,中间加速,然后减速到结束
UIViewAnimationCurveEaseIn, // slow at beginning 缓慢开始,加速到结束
UIViewAnimationCurveEaseOut, // slow at end 加速开始,加速到结束
UIViewAnimationCurveLinear //正常速度
};
十、+ (void)setAnimationRepeatCount:(float)repeatCount;设置动画在动画模块中的重复次数
[UIView setAnimationRepeatCount:3.00];
十一、+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses; 设置动画块中的动画效果是否自动重复播放
[UIView setAnimationRepeatAutoreverses:NO];
十二、+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState; 设置动画是否从当前状态开始播放。
[UIView setAnimationBeginsFromCurrentState:NO];
十三、+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache; //在动画块设置过渡效果
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:insertDemoOne cache:NO];
transition
把一个过渡效果应用到视图中。值定义在UIViewAnimationTransition结构体中。
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
UIViewAnimationTransitionNone, 没有过渡
UIViewAnimationTransitionFlipFromLeft, 翻转视图从左到右
UIViewAnimationTransitionFlipFromRight, 翻转视图从右到左
UIViewAnimationTransitionCurlUp, 从上卷动
UIViewAnimationTransitionCurlDown, 从下卷动
};
view
需要过渡的视图对象。
cache
如果是YES,那么在开始和结束图片视图渲染一次并在动画中创建帧;否则,视图将会在每一帧都渲染。例如缓存,你不需要在视图转变中不停的更新,你只需要等到转换完成再去更新视图。
1、开始一个动画块。
2、在容器视图中设置转换。
3、在容器视图中移除子视图。
4、在容器视图中添加子视图。
5、结束动画块。
十四、+ (void)setAnimationsEnabled:(BOOL)enabled; 设置是否开启动画,默认YES,开启
[UIView setAnimationsEnabled:YES];
十五、+ (BOOL)areAnimationsEnabled; 验证动画是否开启,YES:开启 NO:关闭
BOOL demoBool;
demoBool = [UIView areAnimationsEnabled];
(NSTimeInterval)duration
动画时间
(NSTimeInterval)delay
延迟时间
(UIViewAnimationOptions)options 动画参数
typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {
UIViewAnimationOptionLayoutSubviews = 1 << 0,
UIViewAnimationOptionAllowUserInteraction = 1 << 1, // turn on user interaction while animating
UIViewAnimationOptionBeginFromCurrentState = 1 << 2, // start all views from current value, not initial value
UIViewAnimationOptionRepeat = 1 << 3, // repeat animation indefinitely
UIViewAnimationOptionAutoreverse = 1 << 4, // if repeat, run animation back and forth
UIViewAnimationOptionOverrideInheritedDuration = 1 << 5, // ignore nested duration
UIViewAnimationOptionOverrideInheritedCurve = 1 << 6, // ignore nested curve
UIViewAnimationOptionAllowAnimatedContent = 1 << 7, // animate contents (applies to transitions only)
UIViewAnimationOptionShowHideTransitionViews = 1 << 8, // flip to/from hidden state instead of adding/removing
UIViewAnimationOptionCurveEaseInOut = 0 << 16, // default
UIViewAnimationOptionCurveEaseIn = 1 << 16,
UIViewAnimationOptionCurveEaseOut = 2 << 16,
UIViewAnimationOptionCurveLinear = 3 << 16,
UIViewAnimationOptionTransitionNone = 0 << 20, // default
UIViewAnimationOptionTransitionFlipFromLeft = 1 << 20,
UIViewAnimationOptionTransitionFlipFromRight = 2 << 20,
UIViewAnimationOptionTransitionCurlUp = 3 << 20,
UIViewAnimationOptionTransitionCurlDown = 4 << 20,
UIViewAnimationOptionTransitionCrossDissolve = 5 << 20,
UIViewAnimationOptionTransitionFlipFromTop = 6 << 20,
UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20,
} NS_ENUM_AVAILABLE_IOS(4_0);
(void))animations
动画效果块
可以设置属性如下:
frame
bounds
center
transform
alpha
backgroundColor
contentStretch
completion:(void (^)(BOOL finished))completion
动画结束块
[UIView animateWithDuration: 2.00 delay:3.00 options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
insertDemoTwo.alpha = 0.1;
insertDemoOne.alpha = 1.0;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:3.00
animations:^{
insertDemoTwo.center = CGPointMake(500.0, 470.0);
insertDemoOne.center = CGPointMake(140.0, 100.0);
}
];
}
];
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0 动画效果处理块(无延迟,无参数)
[UIView animateWithDuration:3.00
animations:^{
insertDemoOne.alpha = 1.0;
insertDemoTwo.alpha = 0.1;
}
completion:^(BOOL finished) {
insertDemoTwo.center = CGPointMake(500.0, 470.0);
insertDemoOne.center = CGPointMake(140.0, 100.0);
}
];
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL 动画效果处理块(简单版)
[UIView animateWithDuration:5.00 animations:^{
insertDemoTwo.alpha = 0.1;
insertDemoOne.alpha = 1.0;
}];
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); 过渡动画效果块
[UIView transitionWithView:insertDemoOne duration: 1.0 options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[insertDemoTwo removeFromSuperview];
[insertDemoOne addSubview:insertDemoTwo];
}
completion:^(BOOL finished) {
insertDemoOne.backgroundColor = [UIColor brownColor];
}];
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // toView added to fromView.superview, fromView removed from its superview 视图之间切换的过渡动画效果块