我有一系列UIImages,我需要用它来模拟深度.我无法使用缩放,因为我需要能够旋转父视图,并且图像应该看起来像是在彼此前面明显堆叠,而不是在同一平面上.
我创建了一个新的基于ViewController的项目并将其放在viewDidLoad中(以及附加的三个120x120像素图像,名为1.png,2.png和3.png):
- (void)viewDidLoad {
// display image 3
UIImageView *three = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"3.png"]];
three.center = CGPointMake(160 + 60, 240 - 60);
[self.view addSubview:three];
// rotate image 3 around the z axis
// THIS IS INCORRECT
CATransform3D theTransform = three.layer.transform;
theTransform.m34 = 1.0 / -1000;
three.layer.transform = theTransform;
// display image 2
UIImageView *two = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
two.center = CGPointMake(160, 240);
[self.view addSubview:two];
// display image 1
UIImageView *one = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
one.center = …Run Code Online (Sandbox Code Playgroud) 我有一个相当复杂的UIImageViews 层次结构.最初,当一个人UIImageView在另一个人面前移动时,我正在仔细地交换兄弟姐妹的命令.然后我发现了myUIImageView.layer.zPosition并转而使用它.工作得更简单.它甚至几乎一直都在工作.我从这个问题中发现,zPosition只能在兄弟层中使用.大!所以我真的有两个问题:有没有关于此的实际文档?并且,我可以使用某种软糖来实现这一点吗?(比如将我的所有UIImageViews添加到永远不可见的UIView).Thx提前.