I have been trying to perform a perspective transform on a 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, e.g.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With