首页 / IOS / iOS-UIView动画
iOS-UIView动画
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了iOS-UIView动画,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5482字,纯文字阅读大概需要8分钟。
内容图文
![iOS-UIView动画](/upload/InfoBanner/zyjiaocheng/1331/f3063b1091754b4d813f069fc0545992.jpg)
iOS-UIView动画
今天的主题是UIView的动画。
在iOS中UIView的动画是基于CALayer动画封装。
动画就是静态的图片通过一定频率显示,给人们动画的效果。
UIView动画有基于类方法的实现和基于Block方法块的实现。
一.UIView基于类方法的实现的使用
类方法列表:
@interface UIView(UIViewAnimation) + (void)beginAnimations:(NSString *)animationID context:(void *)context; // additional context info passed to will start/did stop selectors. begin/commit can be nested + (void)commitAnimations; // starts up any animations when the top level animation is commited // no getters. if called outside animation block, these setters have no effect. + (void)setAnimationDelegate:(id)delegate; // default = nil + (void)setAnimationWillStartSelector:(SEL)selector; // default = NULL. -animationWillStart:(NSString *)animationID context:(void *)context + (void)setAnimationDidStopSelector:(SEL)selector; // default = NULL. -animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context + (void)setAnimationDuration:(NSTimeInterval)duration; // default = 0.2 + (void)setAnimationDelay:(NSTimeInterval)delay; // default = 0.0 + (void)setAnimationStartDate:(NSDate *)startDate; // default = now ([NSDate date]) + (void)setAnimationCurve:(UIViewAnimationCurve)curve; // default = UIViewAnimationCurveEaseInOut + (void)setAnimationRepeatCount:(float)repeatCount; // default = 0.0. May be fractional + (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses; // default = NO. used if repeat count is non-zero + (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState; // default = NO. If YES, the current view position is always used for new animations -- allowing animations to "pile up" on each other. Otherwise, the last end state is used for the animation (the default). + (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache; // current limitation - only one per begin/commit block + (void)setAnimationsEnabled:(BOOL)enabled; // ignore any attribute changes while set. + (BOOL)areAnimationsEnabled; + (void)performWithoutAnimation:(void (^)(void))actionsWithoutAnimation NS_AVAILABLE_IOS(7_0); @end
1.+ (void)beginAnimations:(NSString *)animationID context:(void *)context;
该方法是动画的起点,它总是和commitAnimation成对出现。
2.+ (void)commitAnimations
提交动画,
其他的主要是用来设置动画的代理,执行时间,延迟执行动画,是否自动的重复,重复的次数等。下面是它们的使用。
-(void)classMethodAnimation{ [UIView beginAnimations:@"animation" context:nil]; //设置动画重复次数 [UIView setAnimationRepeatCount:10.]; //开始动画改变它的位置从originPoint(0,0)变味originPoint(100,100) anim.frame = CGRectMake(100, 100, 50, 50); //设置动画曲线,也就是动画效果 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //设置动画延迟 [UIView setAnimationDelay:4]; //设置动画代理 [UIView setAnimationDelegate:self]; //设置动画停止时的时间 [UIView setAnimationDidStopSelector:@selector(animationStop)]; //设置动画执行时间 [UIView setAnimationDuration:10]; //设置动画是否自动反转 [UIView setAnimationRepeatAutoreverses:YES]; //设置动画开始时调用的方法 [UIView setAnimationWillStartSelector:@selector(startAnimation)]; [UIView commitAnimations]; }
控制台运行输出结果:(主要是动画代理方法的调用,动画效果见demo)
2015-04-06 08:28:14.230 ViewAnimation[1299:49180] 动画停止了-[ViewController startAnimation]
2015-04-06 08:28:16.227 ViewAnimation[1299:49180] 动画停止了-[ViewController animationStop]
二.UIView动画block方法
@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); // toView added to fromView.superview, fromView removed from its superview + (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
-(void)blockAnimation{ [UIView animateWithDuration:5 animations:^{ anim.frame = CGRectMake(100, 100, 50, 50); }]; [UIView animateWithDuration:5 animations:^{ anim.frame = CGRectMake(200, 200, 50, 50); anim.backgroundColor = [UIColor grayColor]; } completion:^(BOOL finished) { NSLog(@"block animation complet operation"); }]; }
运行控制态输出效果:
2015-04-06 08:33:49.944 ViewAnimation[1359:51632] block animation complet operation
两个动画小结:
通过block把动画内容包含到block中实现动画,使用beginAnimation和commitsAnimation函数对包含动画,都是通过参数设置动画的执行属性。
原文:http://blog.csdn.net/fanyiyao980404514/article/details/44899423
内容总结
以上是互联网集市为您收集整理的iOS-UIView动画全部内容,希望文章能够帮你解决iOS-UIView动画所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。