首页 > 其他 > 详细

UIView动画分析

时间:2015-08-29 18:36:09      阅读:120      评论:0      收藏:0      [点我收藏+]
 1 // UIView动画分析
 2 
 3 #import "ViewController.h"
 4 
 5 @interface ViewController ()
 6 
 7 @property (nonatomic,strong) UIView *myView;
 8 
 9 @end
10 
11 @implementation ViewController
12 
13 
14 
15 // 懒加载是get方法啊
16 -(UIView *)myView{
17     if (_myView == nil) {
18         _myView = [[UIView alloc]init];
19         _myView.backgroundColor = [UIColor orangeColor];
20         _myView.frame = CGRectMake(100, 100, 100, 100);
21     }
22     return _myView;
23 }
24 
25 
26 
27 -(void)viewDidLoad {
28     [super viewDidLoad];
29     self.myView.center = CGPointMake(self.view.center.x, 0);
30      [self.view addSubview:_myView];
31 }
32 
33 -(void)touchesBegan:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
34     
35     NSLog(@"begin");
36     [UIView animateWithDuration:2.0 delay:0.0 usingSpringWithDamping:0.5 initialSpringVelocity:10.0 options:0 animations:^{
37         NSLog(@"开始动画");
38         self.myView.center = self.view.center;
39     } completion:^(BOOL finished) {
40         NSLog(@"完成动画");
41     }];
42     NSLog(@"over");
43  
44 }
45 @end

结论:

技术分享

block是一个C语言的预先准备好的代码在需要的时候执行。而UIView系统封装的动画是立即执行。所以在回调中写了代码后就立马执行的。一开始是begin,接下来是开始动画,然后异步over,再完成动画。

UIView动画分析

原文:http://www.cnblogs.com/aixiaoxin/p/4769455.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!