1

当我旋转踏板时,我正在尝试旋转自行车车轮。

当我逆时针旋转时,没有问题。

但是当我顺时针旋转大约 2-3 秒时,图像开始以快速逆时针旋转。

当我尝试记录 angleInRadians 值时:逆时针旋转时,angleInRadians 值最多从 -0.05 变化到 -0.1。angleInRadians 值在开始时将在 0.05 到 0.1 之间,但突然值变为 -6.1,-6.2 类似的值。请参阅下面的日志。

我改变了图像的锚点。我不确定这是否重要。

对不起我的英语和格式不好

- (void) viewDidLoad
{
    [super viewDidLoad];
    self.PedalTurn.layer.anchorPoint = CGPointMake(0.5, 0.6);
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    CGPoint center = CGPointMake(CGRectGetMidX(self.PedalTurn.bounds), CGRectGetMidY(self.PedalTurn.bounds));
    CGPoint currentPoint = [touch locationInView:self.PedalTurn];
    CGPoint previousPoint = [touch previousLocationInView:self.PedalTurn];
    CGFloat angleInRadians = atan2f(currentPoint.y - center.y, currentPoint.x - center.x) - atan2f(previousPoint.y - center.y, previousPoint.x - center.x);
    self.PedalTurn.transform = CGAffineTransformRotate(self.PedalTurn.transform, angleInRadians);
}

Angle in radians: 0.110071
Angle in radians: 0.0984247
Angle in radians: 0.107355
Angle in radians: 0.118767
Angle in radians: 0.121201
Angle in radians: 0.112823
Angle in radians: 0.0899732
Angle in radians: 0.0883234
Angle in radians: 0.105448
Angle in radians: 0.0884745
Angle in radians: 0.0983613
Angle in radians: 0.108684
Angle in radians: 0.119307
Angle in radians: 0.108768
Angle in radians: 0.111302
Angle in radians: 0.145414
Angle in radians: -6.14848
Angle in radians: -6.13048
Angle in radians: -6.12109
Angle in radians: -6.14578
Angle in radians: -6.13917
Angle in radians: -6.11675
Angle in radians: -6.13025
Angle in radians: -6.15015
Angle in radians: -6.14989
Angle in radians: -6.15097
Angle in radians: -6.14732
Angle in radians: -6.15547
Angle in radians: -6.136
Angle in radians: -6.13241
4

2 回答 2

0
于 2013-04-13T17:10:53.650 回答
0

atan2 的极限是 pi,所以当你达到 pi 的阈值(圆圈左侧的水平)时,发生的是你的 lastTouch 在第二象限真的接近 180 度,而你当前的触摸在第三象限真的接近-180度。在 atan2 http://en.wikipedia.org/wiki/Atan2上阅读此处。

根据您的 angleInRadians,179.99 - (-179.99) = 359.98,或大约 2pi,即 ~6.28。因此,当您达到该阈值时,您实际上添加了接近 2pi,这就是大约 6.xxx 的来源。

于 2014-11-29T05:00:22.530 回答