iOS开发 - UIView动画扩展块(UIViewAnimationWithBlocks)

来源:互联网 发布:怎么卸载kingroot软件 编辑:程序博客网 时间:2024/05/15 07:37

UIView类函数原型

@interface UIView(UIViewAnimationWithBlocks)+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(7_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);+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);+ (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray *)views options:(UIViewAnimationOptions)options animations:(void (^)(void))parallelAnimations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);@end

UIView Animation 的参数详解

##

//设置动画持续的时间[UIView setAnimationDuration:0.2];//设置代理//动画块的某个方法(最下方),委托到本类的实例[UIView setAnimationDelegate:self];//动画结束后去执行的方[UIView setAnimationDidStopSelector:@selector(resetView)];//设置动画的次数[UIView setAnimationRepeatCount:99999999];//设置动画的方式[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//default = 0.0延迟多少时间开始执行动画+ (void)setAnimationDelay:(NSTimeInterval)delay; //default = now ([NSDate date])动画开始日期+ (void)setAnimationStartDate:(NSDate *)startDate; // //default = NO. YES的话,动画(非最后一次)结束后动态复原到最开始状态+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses;//default = NO. YES,停止之前的动画,从现在这里开始新动画+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState; //添加动画到view上,cache是YES的时候比较高效,但是动画过程中不能更新界面上的内容,NO时每一帧都重新画,可以实时更新+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache; //是否忽略一些动画设置+ (void)setAnimationsEnabled:(BOOL)enabled; 

UIViewAnimationWithBlocks动画扩展详解

函数原型

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations

例如一个视图淡出屏幕,另外一个视图出现的代码:

[UIView animateWithDuration:1.0 animations:^{        firstView.alpha = 0.0;        secondView.alpha = 1.0;}];

实现连续的动画,只需在completion代码块中添加动画。
实例代码:

[UIView animateWithDuration:2.0                 animations:^{                     oldImageView.alpha = 0.0;                     newImageView.alpha = 1.0;                     //imageView.center = CGPointMake(500.0, 512.0);                 }                 completion:^(BOOL finished){                     [UIView animateWithDuration:4.0                                      animations:^{                                          newImageView.center = CGPointMake(500.0, 512.0);                                      }];                 }];

UIView视图的动画功能,可以使在更新或切换视图时有放缓节奏、产生流畅的动画效果,进而改善用户体验。UIView可以产生动画效果的变化包括:

可以设置动画属性的有:

 - frame            //大小变化:改变视图框架(frame)和边界。 - bounds           //拉伸变化:改变视图内容的延展区域。 - center           //居中显示 - transform        //旋转:即任何应用到视图上的仿射变换(transform) - alpha            //改变透明度:改变视图的alpha值。 - backgroundColor  //改变背景颜色 - contentStretch   //拉伸内容

其中:

 1. duration   //为动画持续的时间。  2. animations //为动画效果的代码块。 3. completion //为动画执行完毕以后执行的代码块 4. options    //为动画执行的选项 5. delay      //为动画开始执行前等待的时间
0 0
原创粉丝点击