1 // 第一种方式:头尾式
2
3 // 开始动画
4 [UIView beginAnimations:nil context:nil];
5 // 设置动画的时间
6 [UIView setAnimationDuration:2.0];
7 // CGRect frame = self.redView.frame;
8 // frame.origin.y += 100;
9 // self.redView.frame = frame;
10
11 // 提交动画
12 [UIView commitAnimations];
13
14
15 // 第二种方式:block式
16
17 [UIView animateWithDuration:1.0 animations:^{
18 // CGRect frame = self.redView.frame;
19 // frame.origin.y += 100;
20 // frame.size = CGSizeMake(10, 10);
21 // self.redView.alpha = 0.0;
22 // self.redView.frame = frame;
23 }];
24
25
26
27 [UIView animateWithDuration:1.0 animations:^{
28 // CGRect frame = self.redView.frame;
29 // frame.origin.y += 100;
30 // self.redView.frame = frame;
31 } completion:^(BOOL finished) {
32 // 动画完毕后会调用这个block
33 NSLog(@"动画完毕");
34 }];
35
36
37 // 2秒后开始动画(动画的持续时间是1秒)
38 [UIView animateWithDuration:1.0 delay:0.0 options:kNilOptions animations:^{
39 // CGRect frame = self.redView.frame;
40 // frame.origin.y += 100;
41 // self.redView.frame = frame;
42 self.redView.alpha = 0.0;
43 // self.redView.hidden = YES;
44 } completion:nil];
45 }
46
47 [UIView animateKeyframesWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options:<#(UIViewKeyframeAnimationOptions)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>]