1

I need to make a rectangular view [ ] appear as if it's top is rotated back, while the bottom is pinned in place: / \ . The resulting image is isometric with the bottom being wider than the top.

Which CGAffineTransform do I need to accomplish this goal?

Alex Stone
  • 46,408
  • 55
  • 231
  • 407
  • posting sample image can give more understanding of the problem. – Vignesh May 23 '12 at 18:05
  • 6
    What you're attempting to do sounds like a perspective projection transformation, which by definition is not affine. I think you will need to do a little bit more than a single transformation to achieve this in a standard view object – Dan F May 23 '12 at 18:08
  • You can add transformations for CALayer associated with this view. CALayer supports CATransform3D – voromax May 23 '12 at 19:50

2 Answers2

2

As others have pointed out, you can't do this with a CGAffineTransform.

However, it's relatively easy to do with a CATransform3D, as I describe in this answer. You'll need to adjust the m34 component of the CATransform3D to give the transform some degree of perspective, rotate the view about the X axis, and potentially scale it so that the bottom edge remains at the same width as for your original unrotated view.

Alternatively, you might be able to adjust the anchorPoint of your view's underlying layer to be at the bottom, rather than the center. Rotations will then be applied from that edge, which should keep the bottom edge length constant and give you a receding perspective effect for the view. I believe a value of (0.5, 1.0) will set the anchorPoint to the lower edge.

Community
  • 1
  • 1
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
0

Brad, I found this example (by you!) on how to do a perspective transformation:

http://www.sunsetlakesoftware.com/2008/10/22/3-d-rotation-without-trackball

For some reason it does not work in my code. My buttons have the 3d transform applied, but not the scaling effect.

Alex Stone
  • 46,408
  • 55
  • 231
  • 407