【发布时间】:2010-05-14 14:41:29
【问题描述】:
我有一系列 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 = CGPointMake(160 - 60, 240 + 60);
[self.view addSubview:one];
// rotate image 3 around the z axis
// THIS IS INCORRECT
theTransform = one.layer.transform;
theTransform.m34 = 1.0 / 1000;
one.layer.transform = theTransform;
// release the images
[one release];
[two release];
[three release];
// rotate the parent view around the y axis
theTransform = self.view.layer.transform;
theTransform.m14 = 1.0 / -500;
self.view.layer.transform = theTransform;
[super viewDidLoad];
}
我有非常具体的原因为什么我不使用 EAGLView 以及为什么我不将图像作为 CALayers 加载(即为什么我对每个图像都使用 UIImageViews)。这只是一个快速演示,我可以用它来确定我在父应用程序中需要什么。
是否有一些矩阵方法可以沿 z 轴平移这些 2d 图像,使它们看起来像我想要表示的那样?我浏览了其他 StackOverflow 文章以及 Wikipedia 参考资料,但没有找到我正在寻找的内容——尽管我可能不一定会为我正在尝试做的事情使用正确的术语。
【问题讨论】:
标签: iphone core-animation