UI基础 - 训练营:使用CABasicAnimation实现视图绕X/Y轴旋转(3D效果)

视图 3D 旋转

1 - 以绕 X 轴旋转为例

复制代码
 1 #import "ViewController.h"
 2 @interface ViewController ()
 3 @property(strong,nonatomic)UIImageView *logoIV;
 4 
 5 @end
 6 
 7 @implementation ViewController
 8 
 9 - (void)viewDidLoad {
10     [super viewDidLoad];
11     self.view.backgroundColor = [UIColor whiteColor];
12 
13     // 视图
14     self.logoIV = [[UIImageView alloc] initWithFrame:CGRectMake(60, 200, self.view.frame.size.width - 120, self.view.frame.size.width - 120)];
15     self.logoIV.backgroundColor = [UIColor yellowColor];
16     [self.view addSubview:_logoIV];
17 
18     // 动画配置
19     CABasicAnimation *rotationAnimation;
20     // transform.rotation.y 环 Y 轴立体旋转
21     rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];// 绕 X 轴立体旋转
22     rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
23     rotationAnimation.duration = 3;
24     rotationAnimation.cumulative = YES;
25     rotationAnimation.repeatCount = MAXFLOAT;
26 
27     rotationAnimation.removedOnCompletion = NO; // 防止程序 前后台切换后动画静止
28     [self.logoIV.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
29     self.logoIV.layer.shadowOpacity = 1; // 阴影透明度
30     self.logoIV.layer.shadowColor = [UIColor blueColor].CGColor;  // 阴影颜色
31     self.logoIV.layer.shadowRadius = 50; // 阴影半径
32     self.logoIV.layer.cornerRadius = (self.view.frame.size.width - 120)*0.5;
33     self.logoIV.layer.borderColor = [UIColor greenColor].CGColor; // 边框颜色
34     self.logoIV.layer.borderWidth = 20;  // 边框半径
35 
36 }
37 
38 
39 @end
复制代码

运行效果

 

posted on   低头捡石頭  阅读(125)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2017-11-01 Xcode - storyboard_OC版 03:TableViewCell(定制 | 数据绑定:Tag)
2017-11-01 Xcode - storyboard_OC版 02:TabBarController | TableViewController
2017-11-01 Xcode - Storyboard_OC版 01:工作原理
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示