iOS核心笔记——核心动画-CATransition
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS核心笔记——核心动画-CATransition相关的知识,希望对你有一定的参考价值。
1、CATransition介绍:
2、简单使用:
2-1、在storyboard中搭建界面:
2-2、实现转场动画:
1.#import "ViewController.h"
2.
[email protected] ViewController ()
[email protected] (weak, nonatomic) IBOutlet UIImageView *imageView;
5.
6./** 图片索引 */
[email protected] (assign, nonatomic) NSInteger index;
[email protected]
9.
[email protected] ViewController
11.
12.- (void)viewDidLoad {
13. [super viewDidLoad];
14. self.imageView.image = [UIImage imageNamed:@"girl1"];
15.
16.}
17.
18.- (IBAction)next {
19. self.index++;
20. if (self.index == 9) {
21. self.index = 0;
22. }
23. NSString *imageName = [NSString stringWithFormat:@"girl%zd", self.index + 1];
24. self.imageView.image = [UIImage imageNamed:imageName];
25.
26. // 1. 创建动画
27. CATransition *anim = [CATransition animation];
28.
29.// anim.type = kCATransitionMoveIn;
30. anim.type = @"cube";
31.
32. anim.duration = 1.0;
33.
34. // 2. 添加动画
35. [self.imageView.layer addAnimation:anim forKey:nil];
36.}
37.
38.- (IBAction)forward {
39. self.index--;
40. if (self.index == -1) {
41. self.index = 8;
42. }
43. NSString *imageName = [NSString stringWithFormat:@"girl%zd", self.index + 1];
44. self.imageView.image = [UIImage imageNamed:imageName];
45.
46. // 1. 创建动画
47. CATransition *anim = [CATransition animation];
48.
49. // anim.type = kCATransitionMoveIn;
50. anim.type = @"cube";
51. anim.subtype = kCATransitionFromLeft;
52. anim.duration = 1.0;
53.
54. // 2. 添加动画
55. [self.imageView.layer addAnimation:anim forKey:nil];
56.}
[email protected]
效果示例图:
以上是关于iOS核心笔记——核心动画-CATransition的主要内容,如果未能解决你的问题,请参考以下文章