Block动画 和 Spring动画

Block动画:

 1 @interface BlockViewController ()
 2 @property (weak, nonatomic) IBOutlet UIView *playView;
 3 
 4 @end
 5 
 6 @implementation BlockViewController
 7 
 8 - (void)viewDidLoad {
 9 
10     [super viewDidLoad];
11     // Do any additional setup after loading the view from its nib.
12 }
13 
14 - (void)didReceiveMemoryWarning {
15     [super didReceiveMemoryWarning];
16     // Dispose of any resources that can be recreated.
17 }
18 #pragma mark - 简单动画
19 - (IBAction)easyBlock:(id)sender {
20     // 第一个参数:设置动画时长
21     // 第二个参数:动画要显示的效果
22     // 第三个参数:动画完成时进行的事情
23     __weak typeof (self)weakSelf = self;
24     [UIView animateWithDuration:2.0 animations:^{
25         weakSelf.playView.center = weakSelf.view.center;
26     } completion:^(BOOL finished) {
27         
28         NSLog(@"位置变了");
29     }];
30 }
31 #pragma mark - 复杂动画
32 - (IBAction)complexBlock:(id)sender {
33     // 参数1:时长
34     // 参数2:动画延迟时间
35     // 参数3:动画的枚举值
36     // 参数4:要实现的动画效果
37     // 参数5:动画完成是要进行的事情
38     __weak typeof (self)weakSelf = self;
39     [UIView animateWithDuration:5.0f delay:1.0f options:UIViewAnimationOptionOverrideInheritedOptions animations:^{
40         weakSelf.playView.frame = CGRectMake(300, 100, 10, 10);
41     } completion:^(BOOL finished) {
42         NSLog(@"变小了");
43     }];
44 }
45 #pragma mark - 关键帧动画
46 - (IBAction)keyFramesBlock:(id)sender {
47     // 参数1:时长
48     // 参数2:动画的延迟时间
49     // 参数3:枚举值
50     // 参数4:开始动画
51     __weak typeof(self)weakSelf = self;
52     [UIView animateKeyframesWithDuration:3.0f delay:1.0f options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
53         
54         // 在这个里面需要加一个方法,即创建block的关键帧
55         // 参数1:帧动画的开始时间
56         // 参数2:帧动画的持续时间
57         // 参数3:实现的效果
58         [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5 animations:^{
59             // 实现的效果
60             weakSelf.playView.frame = CGRectMake(100, 200, 50, 80);
61         }];
62     } completion:^(BOOL finished) {
63         NSLog(@"哈哈哈");
64     }];
65 }

Spring动画简介:

代码展示:

 1 @interface SpringViewController ()
 2 // 设置一个ImageView属性
 3 @property (weak, nonatomic) IBOutlet UIImageView *springImageView;
 4 
 5 @end
 6 
 7 @implementation SpringViewController
 8 
 9 - (void)viewDidLoad {
10     [super viewDidLoad];
11     self.title = @"spring 动画";
12     // Do any additional setup after loading the view from its nib.
13     // 参数1: 动画时长
14     // 参数2: 延迟时间
15     // 参数3: 类似弹簧的效果值 0 - 1
16     // 参数4: 初始化spring的一个速度
17     // 参数5: spring动画的枚举值
18     // 参数6: 开始动画
19     // 参数7: 动画完成
20     __weak typeof(self) weakSelf = self;
21     [UIView animateWithDuration:5.0f delay:0.1f usingSpringWithDamping:1.0 initialSpringVelocity:10 options:UIViewAnimationOptionOverrideInheritedOptions animations:^{
22         weakSelf.springImageView.center = weakSelf.view.center;
23     } completion:^(BOOL finished) {
24         NSLog(@"tantnatan");
25     }];
26 }
原文地址:https://www.cnblogs.com/crazygeek/p/5535863.html