2

I'm trying to rotate a UIView object like shown on the image below http://i.piccy.info/i7/f8ff7fe488c7c492e6ff6a689bc9cdeb/1-5-2127/60800682/rotation.png

I'm trying to use the CALayer's transform but I get something like this: http://i.piccy.info/i7/bbb672b058fdfdd251cc90f1ce2b9c1f/1-5-2128/9488743/rotate2.png

Cœur
  • 37,241
  • 25
  • 195
  • 267
Oleg
  • 1,383
  • 4
  • 19
  • 35

1 Answers1

1

If I understand correctly, you want to title the view backwards (into the screen) an should be able to achieve it something like this:

float distance = 50;

CATransform3D basicTrans = CATransform3DIdentity;
basicTrans.m34 = 1.0 / -distance;
view.layer.transform = CATransform3DRotate(basicTrans, M_PI_4, 1.0f, 0.0f, 0.0f);

To achieve this effect you need to manipulate one of the transformation values directly (m34). The lower distance gets, the stronger the effect gets. Then you can do the rotation transformation around the x axis (to tilt), in this case PI/4 or 45 degrees. You can calculate arbitrary values pi using degrees * M_PI / 180.0.

Dennis Bliefernicht
  • 5,147
  • 1
  • 28
  • 24
  • When view rotates it's height is changing. How can I calculate M_PI value if I have fixed new (after rotation) height – Oleg Nov 25 '11 at 16:31
  • I think trigonometry gives us: `angle = M_PI_4 - asin(newHeight / height)` where `newHeight` should be smaller than `height` but greater than zero. – Dennis Bliefernicht Nov 25 '11 at 16:48