views:

560

answers:

2

Hi,

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.

+1  A: 

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.

Daniel
A: 

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).

eOgas