views:

40

answers:

2

Hi,

I am using

float theAngle = atan2( location.y-self.center.y, location.x-self.center.x ); 

to rotate a wheel at a certain angle.

and

self.transform = CGAffineTransformMakeRotation(angleRadians);

for the transformation to take place.

But everytime the user represses the wheel to turn it, it goes back to the original location and starts from there. How may I stop this from happening please?

Thanks!

+1  A: 

I would hazzard a guess that the reason is that you are calculating based on the original position of the wheel rather than the previous position of the wheel.

i.e. Presuming that self.center represents the original position of the wheel as first displayed, location represents the users desired new rotation and looking up atan2 on wikipedia (trig is not my strong point :-) I would guess you need self.location to be updated each time to the be location so that the next rotation starts from the last rotation.

Just a guess :-)

Derek Clarkson
+1  A: 

You may setting the rotation angle value of the wheel rather than adding the value to the current angle.

brutella
I'm using self.transform = CGAffineTransformMakeRotation(angleRadians); for the transformation
Lily
That transform is always based on the original position of your view, hence the current behavior.
Yannick Compernol
can you offer an alternative please?
Lily
I don't know how you calculate the angle but you have to remember the angle when the user releases the wheel. you can also try to get the rotation angle of the layer by NSValue* value = [layer valueForKey:@"transform.rotation.z"];
brutella