0

Simply trying to rotate a rectangle around it's origin, or its upper left corner like so:

enter image description here

Am using the following:

panGestureRecognizer.view.transform = CGAffineTransformRotate(panGestureRecognizer.view.transform, (M_PI * angle) / 180);

But the rectangle is sort of rotating in a big loop. Is there some sort of translation I need to do to get this to work?

Ser Pounce
  • 14,196
  • 18
  • 84
  • 169

1 Answers1

1

You just need to set the anchor point: https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instp/CALayer/anchorPoint

panGestureRecognizer.view.layer.anchorPoint = CGPointMake(0.0, 0.0);

Further Reading: For more advanced stuff you could try some of the tips detailed here for matrix transformations: https://stackoverflow.com/a/8536553/563381

Community
  • 1
  • 1
Ryan Poolos
  • 18,421
  • 4
  • 65
  • 98
  • Thanks. I did try this, but it didn't work. Possible I need to set something else as well? – Ser Pounce Mar 06 '13 at 02:41
  • This should be all you need. And you make an image similar to your expected outcome that shows the actual outcome? Might help me better understand whats going wrong. – Ryan Poolos Mar 06 '13 at 13:43
  • Actually the correct answer is: CGPointMake(0,0),it's the view.layer.anchorPoint (you didn't put layer in the above). If you fix those, will mark answer as correct. – Ser Pounce Mar 06 '13 at 19:07
  • Opps, sorry for the typo. Glad you figured it out. – Ryan Poolos Mar 06 '13 at 19:19
  • Also, have to change CGPointMake(0,1.0) to CGPointMake(0,0) that's what gave me the correct response – Ser Pounce Mar 06 '13 at 19:51