Basel
Basel

Reputation: 2368

Changing the anchorpoint and then rotating using CGAffineTransformMakeRotation

I'm trying to rotate a UIView around a different anchor point. When I first create the UIView I set the anchor point to (0.0, 0.5). I rotate the view using CGAffineTransformMakeRotation. When I click on the other side of the UIView, I want to set the anchor point to (1.0, 0.5). This moves the UIView to set the anchor point to the center point. I read on other answers that I should do this: "multiply the bounds' width and height by the old and new anchorPoint's normalized values, take the difference of the two anchorPoints, and apply that difference to the position of the layer"

I tried that but I'm not able to set the UIView to the exact same position. Using this code:

self.transform = CGAffineTransformTranslate(self.transform, self.bounds.size.width, 0);

Set it to the exact same position but. When I rotate again (it should rotate around the new anchor point) it flips the UIView or something strange happens.

Upvotes: 0

Views: 1685

Answers (1)

MHC
MHC

Reputation: 6405

When you re-locate the view due to the change in the anchor point, try not using the transform property. Instead, move your view using the frame property or the center property (or position if you are working with a CALayer object). Also, can you post more code showing how exactly rotate the view?

Upvotes: 1

Related Questions