码迷,mamicode.com
首页 > 其他好文 > 详细

UIKit - UIView动画扩展块(UIViewAnimationWithBlocks)

时间:2015-04-23 15:39:04      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:uiview   duration   动画   block   

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      //为动画开始执行前等待的时间

UIKit - UIView动画扩展块(UIViewAnimationWithBlocks)

标签:uiview   duration   动画   block   

原文地址:http://blog.csdn.net/wangzi11322/article/details/45222163

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!