I have been working in objective-c for a while now, but I haven't really had a need (until now) to dive deeper into core animation and graphic manipulation.
我现在已经在objective-c工作了一段时间,但我并没有真正需要(直到现在)深入研究核心动画和图形操作。
I currently have four UIImageViews that I want to animate into a position that makes them look like they are lying down on a flat surface. What I mean by that is that they will start as rectangles - undistorted and flat on the screen, but will animate into the skewed perspective that makes it look like they are sitting on a flat surface.
我目前有四个UIImageViews,我想动画到一个位置,让他们看起来像是躺在一个平坦的表面上。我的意思是它们将以矩形开始 - 在屏幕上不失真和平坦,但会动画到倾斜的视角,使它看起来像是坐在平坦的表面上。
I believe that CATransform3D is what I need to do and have read a number of docs that all point to using .m34 to create the correct perspective. I just can't seem to get it to work. Below is a snippet of code that I am using just to try and get the image to skew. When I use the code below, just to try and skew the image, it seems to cut it off instead of showing the right perspective.
我相信CATransform3D是我需要做的,并且阅读了许多文档,这些文档都指向使用.m34来创建正确的透视图。我似乎无法让它工作。下面是一段代码,我只是试图让图像偏斜。当我使用下面的代码时,只是为了尝试扭曲图像,它似乎将其剪掉而不是显示正确的透视图。
CATransform3D transform = CATransform3DIdentity;
transform.m34 = -1.0f / 700.0f;
// Perform other transforms
transform = CATransform3DRotate( transform,
degreesToRadians(45.0f), 0.0f, 1.0f, 0.0f);
[layer setTransform:transform];
I can handle the animations fine, but am having trouble getting the final image skewed so that it looks correct. Anyone have any suggestions or samples on how to achieve this?
我可以很好地处理动画,但是无法使最终图像倾斜以使其看起来正确。任何人对如何实现这一点有任何建议或样品?
1 个解决方案
#1
0
The animation looks skewed to me. Try experimenting with the m34 factor to make it skew more (setting it to a lower value like -1.0f/200.0f). Just experiment and you will eventually get it right. You can change to rotation to something else than 45 degrees if you want it to skew more.
动画看起来偏向我。尝试尝试使用m34因子使其更倾斜(将其设置为较低的值,如-1.0f / 200.0f)。只是做实验,你最终会做对。如果您希望它更倾斜,您可以将旋转更改为45度以外的其他值。
If your transform doesn't skew at all then maybe one of your other transforms are overwriting the transform (I.e you are using one of the Make transform calls). If so: try moving the transform.m34 assignment to be the last thing before applying the transform.
如果你的变换完全没有偏斜,那么你的其他变换之一可能会覆盖变换(即你正在使用其中一个Make变换调用)。如果是这样:尝试将transform.m34赋值移动到应用变换之前的最后一项。
#1
0
The animation looks skewed to me. Try experimenting with the m34 factor to make it skew more (setting it to a lower value like -1.0f/200.0f). Just experiment and you will eventually get it right. You can change to rotation to something else than 45 degrees if you want it to skew more.
动画看起来偏向我。尝试尝试使用m34因子使其更倾斜(将其设置为较低的值,如-1.0f / 200.0f)。只是做实验,你最终会做对。如果您希望它更倾斜,您可以将旋转更改为45度以外的其他值。
If your transform doesn't skew at all then maybe one of your other transforms are overwriting the transform (I.e you are using one of the Make transform calls). If so: try moving the transform.m34 assignment to be the last thing before applying the transform.
如果你的变换完全没有偏斜,那么你的其他变换之一可能会覆盖变换(即你正在使用其中一个Make变换调用)。如果是这样:尝试将transform.m34赋值移动到应用变换之前的最后一项。