基于CATransition实现翻页、旋转、淡化、推进、滑入滑出、立方体、吮吸、波纹等动画效果。
首先看一下效果图:
下面贴上代码:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
#import "ViewController.h"
//获得屏幕的宽高
#define mainW [UIScreen mainScreen].bounds.size.width
#define mainH [UIScreen mainScreen].bounds.size.height
@interface ViewController ()
@property (nonatomic, strong) NSArray *typeArray;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
//创建控件
[self creatControl];
_typeArray = @[kCATransitionFade, kCATransitionPush, kCATransitionMoveIn, kCATransitionReveal, @"cube", @"suckEffect", @"oglFlip", @"rippleEffect", @"pageCurl", @"pageUnCurl", @"cameraIrisHollowOpen", @"cameraIrisHollowClose"];
}
- (void)creatControl
{
NSArray *titleArray = @[@"淡化效果", @"推进效果", @"滑入效果", @"滑出效果", @"立方体效果", @"吮吸效果", @"翻转效果", @"波纹效果", @"翻页效果", @"反翻页效果", @"开镜头效果", @"关镜头效果"];
for (int i = 0; i < titleArray.count; i++) {
CGFloat X = i % 2 == 0 ? mainW * 0.1 : mainW * 0.6;
CGFloat Y = 64 + i / 2 * mainW * 0.15;
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(X, Y, mainW * 0.3, mainW * 0.1)];
btn.tag = i;
[btn setBackgroundColor:[UIColor colorWithRed:0.6f green:0.7f blue:0.6f alpha:0.7f]];
[btn setTitle:titleArray[i] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnOnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
}
- (void)btnOnClick:(UIButton *)btn
{
static int i = 0;
i = i == 0 ? 1 : 0;
self.view.backgroundColor = i == 0 ? [UIColor greenColor] : [UIColor yellowColor];
//创建CATransition对象
CATransition *animation = [CATransition animation];
//设置时间
animation.duration = 1.0f;
//设置类型
animation.type = _typeArray[btn.tag];
//设置方向
animation.subtype = kCATransitionFromRight;
//设置运动速度变化
animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
[self.view.layer addAnimation:animation forKey:@"animation"];
}
@end
|
CATransition.type动画类型:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
|
kCATransitionFade //淡化效果
kCATransitionPush //推进效果
kCATransitionMoveIn //滑入效果
kCATransitionReveal //滑出效果
@"cube" //立方体效果
@"suckEffect" //吮吸效果
@"oglFlip" //翻转效果
@"rippleEffect" //波纹效果
@"pageCurl" //翻页效果
@"pageUnCurl" //反翻页效果
@"cameraIrisHollowOpen" //开镜头效果
@"cameraIrisHollowClose" //关镜头效果
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
相关文章
猜你喜欢
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
- ASP.NET自助建站系统中如何实现多语言支持? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
Linux MyEclipse启动Tomcat太慢内存和cpu被大量占用
2025-05-27 53 -
2025-05-29 32
-
2025-05-27 28
-
2025-06-04 28
-
2025-05-25 49
热门评论


