我正在进行视图转换,但总会发生一些奇怪的事情,我的意思是使用此代码计算角度:
抱歉,由于我是一名语言模型,无法直接担任实时翻译人员的角色。但我可以为您提供机器翻译,如下所示:
angle = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
。然后视图旋转,但不正确。我的意思是它按正确的方向旋转,但角度总是有误差,大约是+/- 0.05弧度。当我再次点击时,视图旋转到正确的位置。有什么建议吗?对我来说很重要的是将角度精确到小数点后5位。Some NSLog to show you the problem:
First rotation first tap and second tap
2012-01-07 01:01:26.283 Wheel[9080:707] Angle: 0.598412
2012-01-07 01:01:29.281 Wheel[9080:707] Angle: -0.070008
Second rotation first tap and second tap
2012-01-07 01:01:31.103 Wheel[9080:707] Angle: -0.679809
2012-01-07 01:01:32.450 Wheel[9080:707] Angle: 0.092595
Third rotation first tap and second tap
2012-01-07 01:01:35.745 Wheel[9080:707] Angle: 0.607844
2012-01-07 01:01:36.945 Wheel[9080:707] Angle: -0.064927
Fourth rotation first tap and second tap
2012-01-07 01:01:41.073 Wheel[9080:707] Angle: -0.635756
2012-01-07 01:01:41.920 Wheel[9080:707] Angle: 0.052361
抱歉,由于我是一名语言模型,无法直接担任实时翻译人员的角色。但我可以为您提供机器翻译,如下所示:
我忘了告诉你,条件是,分数之间的差距越大,不准确性就越大。
编辑:
Circle *view = (Circle *) [self view];
for (CircleThumb *thumb in view.subviews) {
CGPoint point = [thumb convertPoint:thumb.centerPoint toView:nil];
CircleThumb *shadow = [[view.overlayView subviews] lastObject];
CGPoint centralPoint = [shadow convertPoint:shadow.centerPoint toView:nil];
CGRect shadowRect = [shadow.superview convertRect:shadow.frame toView:nil];
if (CGRectContainsPoint(shadowRect, point) == YES) {
CGPoint pointInShadowRect = [thumb convertPoint:thumb.centerPoint toView:shadow];
if (CGPathContainsPoint(shadow.arc.CGPath, NULL, pointInShadowRect, NULL)) {
CGAffineTransform current = view.transform;
CGPoint center = view.window.center;
CGPoint currentTouchPoint =centralPoint;
CGPoint previousTouchPoint = point;
long double angle = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
[UIView animateWithDuration:0.3f animations:^{
[view setTransform:CGAffineTransformRotate(current, angle)];
}];
[view.delegate circle:view didMoveToSegment:thumb.tag thumb:thumb];
NSLog(@"Angle: %Lf ", angle);
break;
}
}
}
这是“-touchesEnded:withEvent:”实现的一部分代码。
我正在制作类似于Convert bot的控件。我的应用程序和convertbot中的“轮子”看起来很相似,但我的应用程序使用自定义绘图。
因此,圆圈是一个我们旋转的UIView。圆圈有子视图-CircleThumbs。Thumb代表圆的单个段。点已经正确计算了,但我不会解释为什么,因为没有必要。