iOS开发 - UIView动画扩展块(UIViewAnimationWithBlocks)
2015-04-23 15:18
465 查看
UIView类函数原型
@interface UIView(UIViewAnimationWithBlocks) + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_***AILABLE_IOS(4_0); + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_***AILABLE_IOS(4_0); // delay = 0.0, options = 0 + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_***AILABLE_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_***AILABLE_IOS(7_0); + (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_***AILABLE_IOS(4_0); + (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion NS_***AILABLE_IOS(4_0); + (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray *)views options:(UIViewAnimationOptions)options animations:(void (^)(void))parallelAnimations completion:(void (^)(BOOL finished))completion NS_***AILABLE_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 //为动画开始执行前等待的时间
相关文章推荐
- iOS学习笔记--UIView的常见属性及方法,UIViewAnimationWithBlocks
- UIViewAnimationWithBlocks动画之spring
- UIView类的UIViewAnimationWithBlocks扩展 和 使用core animation
- 父视图 使用 UIViewAnimationWithBlocks 时,如何让子视图无动画
- iOS开发-CALayer/Core Animation/UIView动画封装
- iOS开发--动画(Animation)总结
- ios之UIView执行基础动画Animation使用参数配置
- ios UIView动画 UIViewAnimationOptionskey的意义
- 【深入浅出IOS开发】在UIView中设置动画
- iOS开发基础知识:Core Animation(核心动画)
- ios开发学习--动画(Animation)效果源码分享--系列教程
- iOS开发-UIView之动画效果的实现方法(合集)
- IOS开发-UIView之动画效果的实现方法(合集)
- iOS学习应用开发就业课:第7章_056:UIView动画基础
- iOS 开发之动画篇 - 从 UIView 动画说起
- IOS开发-UIView之动画效果的实现方法(合集)
- swift2.0 CASpringAnimation 和 UIView.animateWithDuration 分别实现弹性动画
- 【iOS开发】---- UIView动画
- ios开发学习--动画(Animation)效果源码分享
- iOS开发UIView的Animation效果