Apply perspective conversion without turning

I am trying to do a perspective conversion on a UIView. I have been working on this.

However, this example applies a rotation on the view, as well as a change in perspective. Is there a way to change the point of view without turning? Something that might look like this:

enter image description here

I try to remove the rotation, but when I do, the perspective transformation does not apply. I can not find any examples that concern simply changing perspectives. Thanks in advance.

+4
source share
2 answers

Just adding the answer to David: To get the result, as in your image, you need to rotate the view around the x axis (horizontal axis) so that the top edge of the view rectangle is displayed "farther" from the viewer than the bottom edge, for example

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; 
+7
source

The perspective will not be visible without any rotation relative to your viewpoint. The prospect is still applied, even if you are not spinning, but it will not be very noticeable.

Another transformation that shows perspective is the translation along Z, which makes the view look like scaling.

0
source

Source: https://habr.com/ru/post/1481545/


All Articles