Ser Pounce
Ser Pounce

Reputation: 14527

Rotate Rectangle Around Its Upper Left Corner

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?

Upvotes: 0

Views: 949

Answers (1)

Ryan Poolos
Ryan Poolos

Reputation: 18551

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

Upvotes: 1

Related Questions