을 ATAN2, 나는이 코드를 사용하여 각도를 계산 의미 :하지만 제대로 angle = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
CGAffineTranformRotate 내가 내보기의 전환을 항상 뭔가 이상한 일이있어 inaccuration
그리고 뷰가 회전합니다. 적절한 방향으로 회전하지만 각도는 항상 +/- 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 :'구현 내가 변환 봇에 유사한 컨트롤을 만들고있어
가. 내 애플 리케이션과 convertbot에서 비슷한 "휠"하지만 내 사용자 정의 드로잉을 사용합니다.
그래서 서클은 회전하는 UIView입니다. 서클에 하위보기가 있습니다. CircleThumbs. thumb은 원의 단일 세그먼트를 나타냅니다. 포인트는 적절히 계산되지만 필요가 없기 때문에 이유를 설명하지 않겠습니다.
위의 정보를 인쇄하는 우편 번호를 게시 할 수 있습니까? 첫 번째와 두 번째 탭은 무엇입니까? – alekhine