I'm trying to understand how to create depth perceptive to my UIView like this :

I've tried this code:
var rotationWithPerspective = CATransform3DIdentity;
rotationWithPerspective.m34 = -1.0/500.0/2/2
rotationWithPerspective = CATransform3DRotate(rotationWithPerspective, 22.5, 0, 1, 0);
preview.layer.transform = rotationWithPerspective
which generates perspective. Yet, it Flips the View for some reason.
1) How can I avoid the "flipping" after the transform?
2) Does the "perspective depth" resulting from the transform, will be the same to every given UIView, or it depends on the UIView size, etc?
Thank YOU!
The CATransform3DRotate expects radians not degrees. You are rotating by 22.5 radians which is like 1200 degrees. That's probably why your image is inverted. You probably want to use this:
let radians = 22.5 * M_PI / 180
rotationWithPerspective = CATransform3DRotate(rotationWithPerspective, radians, 0, 1, 0);
For 2)
You can read more about it in iOS Core Animation - Advanced Techniques by Nick Lockwood. Hope that help.
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