UIRotationGestureRecognizer 旋转有时会达到非常大的值
我正在使用 UIRotationGestureRecognizer
来旋转 UIImageView
。通过将所有小的旋转变化添加到 CGFloat 中,我尝试计算 UIImageView 的总旋转量。它确实很好,但不知何故,手势的旋转属性有时具有非常大的值。通常,当缓慢旋转时,它位于 0.00## 左右,但随后它突然开始给出类似 6.## 的值。最终结果总计> 300 弧度,这太荒谬了——手指移动一毫米就需要超过 47 圈“转”。
有谁知道导致此问题的原因,更重要的是有解决方案吗?
这是一些代码:
if ([gesture state] == UIGestureRecognizerStateBegan || [gesture state] == UIGestureRecognizerStateChanged)
{
totalRotation += [gesture rotation];
NSLog(@"%f", [gesture rotation]);
[gesture view].transform = CGAffineTransformRotate([[gesture view] transform], [gesture rotation]);
[gesture setRotation:0];
}
else
{
NSLog(@"rot: %f", totalRotation);
}
I'm using a UIRotationGestureRecognizer
to rotate a UIImageView
. By adding all small rotation changes to a CGFloat
, I try to calculate the total rotation of the UIImageView
. It does fine, but somehow the rotation
property of the gesture sometimes has a very large value. Normally, when rotating slow, it sits around 0.00##, but then it suddenly starts giving values like 6.##. The end result is a total of > 300 radians, which is ridiculous - over 47 'revolutions' for just a millimeter worth of finger movement.
Does anyone know what causes this, and more importantly, have a solution to it?
Here's some code:
if ([gesture state] == UIGestureRecognizerStateBegan || [gesture state] == UIGestureRecognizerStateChanged)
{
totalRotation += [gesture rotation];
NSLog(@"%f", [gesture rotation]);
[gesture view].transform = CGAffineTransformRotate([[gesture view] transform], [gesture rotation]);
[gesture setRotation:0];
}
else
{
NSLog(@"rot: %f", totalRotation);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也明白了。 6.## 值约为 2 * PI(即 360 度)。根据我的经验,可能是 +/- 6.##。我什至得到了+/- 12.## (4 * PI) 而不是花时间找出原因,我只是检查和纠正:
实际上你不需要这样做,因为你直接使用角度。 Sin(angle +/- PI*2) = Sin(angle) 等等。不要担心 300 弧度,它仍然会得到正确的变换。但我将角度除以 2,所以这对我来说是个问题。
I'm getting this too. The 6.## values are around 2 * PI (ie 360 degrees). Can be +/- 6.## in my experience. I've even got +/- 12.## (4 * PI) Rather than spending time working out why, I'm just checking and correcting:
Actually you shouldn't need to do this because you are using the angle directly. Sin(angle +/- PI*2) = Sin(angle) etc. Don't worry about the 300 radians, it will still get the transform right. But I'm dividing the angle by 2 so this was a problem for me.