[英]Apply a perspective transform without rotating
I have been trying to perform a perspective transform on a UIView. 我一直在尝试对UIView执行透视变换。 I have been working from this example .
我一直在这个例子中工作。
However, that example applies a rotation on the view as well as a perspective change. 但是,该示例在视图上应用旋转以及透视更改。 Is there a way to change the perspective of the view with no rotation?
有没有办法在没有旋转的情况下改变视图的视角? Something that might look like this:
可能看起来像这样的东西:
I have been trying to remove the rotation, but when I do the perspective transform does not get applied. 我一直试图去除旋转,但是当我做透视变换时不会应用。 I can't find any examples out there that deal with just changing the perspective.
我找不到任何只是改变观点的例子。 Thanks in advance.
提前致谢。
Just adding to David's answer: To get an output as in your image you have to rotate the view around the x-axis (the horizontal axis) so that the upper edge of the view rectangle appears "further away" from the viewer than the lower edge, eg 只需添加大卫的答案:要获得图像中的输出,您必须围绕x轴(水平轴)旋转视图,以便视图矩形的上边缘显示“远离观察者”而不是下方边缘,例如
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -200;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0f * M_PI / 180.0f, 1.0f, 0.0f, 0.0f);
layer.transform = rotationAndPerspectiveTransform;
Perspective won't be visible without any rotation relative to your view point. 没有相对于您的视点的任何旋转,透视将不可见。 The perspective does still get applied even when you don't rotate but it won't be very visible.
即使您不旋转,但仍然会应用透视,但它不会非常明显。
One other transform that shows perspective is translating along Z which makes the view look like it is being scaled. 另一个显示透视的变换是沿Z平移,这使得视图看起来像是缩放的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.