Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding CATransform3D

I'm playing with CATransform3DMakeRotation in a UIView, and I'm trying to do a 45º, transform like it's laying backwards:

http://cl.ly/2A2p1W1e2N3a1W181r35

This is the "code" I have, but clearly doesn't do it.

CATransform3D _tr = CATransform3DMakeRotation(3.14/4, 1, 0, 0);
view.layer.transform = _tr;

please help me understand the params. Thanks.

like image 471
Diego Torres Avatar asked Jul 31 '11 05:07

Diego Torres


1 Answers

Basically, your code is correct, but to get the perspective effect, you need to set the sublayerTransform of the superview's layer to something like this:

CATransform3D perspectiveTransform = CATransform3DIdentity;
perspectiveTransform.m34 = 1.0 / -850;
myView.layer.sublayerTransform = perspectiveTransform;

You can experiment with different values for different amounts of distortion.

like image 137
omz Avatar answered Oct 28 '22 23:10

omz