我一直在研究类似于命运之轮的纺车。我几乎破解它,但后来撞到了一堵砖墙。与this文章中提到的问题相同。轮子动画需要来回移动,就好像它正在产生动力,并在释放时它将顺时针转动。使用CGAffineTransformMakeRotation旋转图像
我已经掌握了所有这些工作,但是第一次触摸时,轮子跳起,因为它的起点已经从我的手指触地位置变成了,而不是从它的当前位置开始。我明白为什么要这样做,但我不知道如何让它没有跳跃。
我见过使用UIRotateGestureRecognizer的建议,我发现它的问题是;当您旋转度数增量并且动画变得更快时,当以相反的方式时,您必须从当时的程度减少,这意味着动画从您正在打手势的方向走向错误的方向,直到您递减到负面程度。我确定有可能纠正这些问题,但我现在的解决方案编号非常接近,而不是在有解决方案时重写。
我意识到其他职位使用totalRadians是解决方案,对我来说它不允许逆时针动画。
totalRadians += fabs(theAngle - totalRadians);
totalRadians = fmod(totalRadians, 2*M_PI);
这是我到目前为止。
- (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));
}
任何人谁会照顾帮助? –
Hellllllllllllllllllllllllllllp! –
如果您遇到同样的问题,请按照以下示例进行操作。 http://ericmcconkie.com/2010/03/trig-and-objective-c/ –