Reputation: 4001
I have subclassed UIImageView to create a soccer ball.
The ball bounces and moves along an x & y axis, and depending on where you touch the ball, the ball will move as you'd expect a soccer ball would.
My problem is that I would like to rotate the Ball(UIImageView), but still know the x & y positions from it's original position.
I am rotating it with the following code:
ball.superview.transform = CGAffineTransformMakeRotation(M_PI+(ball.center.x*.015));
ball.transform= CGAffineTransformMakeRotation(M_PI+(ball.center.x*.015));
When I rotate it, the x & y position also rotate. Can I somehow get the x/y distance from the centre of the UIImageView? Any other ideas?
Thanks,
James.
Upvotes: 0
Views: 1157
Reputation: 9132
Why are you rotating the superview also? If you don't do that the center x,y will not be affected.
Upvotes: 0
Reputation: 109
Why not just use ball.center as the position. This way, rotations will have no effect on the position (assuming your image is correctly centered).
Upvotes: 0
Reputation: 22395
I think if you set the anchor of your CALayer of the UIIMageView to be the center of the UIImageView youll be ok, right now its set to the upper left corner and so are expiriencing the x and y moving.
Upvotes: 1