Rotating image using CGAffineTransformMakeRotation
Ive been working on a spinning wheel similar to the wheel of fortune. Ive almost cracked it but then hit a brick wall. Same problem as mentioned in this this post. The wheel animation is required to go back and forth as if it were generating momentum and on release it will turn clockwise.
I have all that working however, on first touch the wheel jumps as its starting point has become from where my finger touchdown rather than from its current standing position. I understand why its doing it but i have no idea how make it so there is no jump.
Ive seen suggestions to use UIRotateGestureRecognizer, the problem i found with it is; as you rotate the degrees increment and the animation gets faster, when going the opposite way you have to decrement from whichever degree you are at that time which means the animation is going in the wrong direction from what you're gesturing until you decrement to a negative degree. Im sure it may be possible to rectify these issues but im so close with my current solution id rather not rewrite if there is a solution.
I realise for the other post to use totalRadians was the solution, for me it didnt allow the anti-clockwise animation.
totalRadians += fabs(theAngle - totalRadians);
totalRadians = fmod(totalRadians, 2*M_PI);
This is what i 开发者_如何学Gohave so far.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:wheelImage];
xleg = location.x-starttoset.x;
yleg = location.y-starttoset.y;
swipetimer = CFAbsoluteTimeGetCurrent();
CGAffineTransform transforms;
location = [touch locationInView:wheelImage];
float theAngle = atan2( location.y-wheelImage.center.y, location.x-wheelImage.center.x );
transforms = CGAffineTransformConcat(spinningWheelImage.transform,CGAffineTransformMakeRotation(theAngle));
}
In order to prevent the jump, you should keep track of the position when the touch starts moving, not when it first happens.
精彩评论