2012-10-16 5 views
2

이 샘플 코드 RotationPie으로 작업하고 있습니다. 그것은 바퀴이며, 프로젝트 내에서 한 방향으로 만 움직이거나 회전시키고 싶습니다. 나는 다른 옵션을 넣고 싶고 사용자는 그 중 하나를 선택해야 할 것이다. 휠을 한 방향으로 만 회전시키고 싶었습니다. 클래스 CDCircleGestureRecognizer에서이 메서드로 무언가를 변경해야한다고 생각하지만 무엇을 모르겠습니다.UIview 데모는 한 방향으로 만 회전하십시오.

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    if ([self state] == UIGestureRecognizerStatePossible) { 
     [self setState:UIGestureRecognizerStateBegan]; 
    } else { 
     [self setState:UIGestureRecognizerStateChanged]; 
    } 

    // We can look at any touch object since we know we 
    // have only 1. If there were more than 1 then 
    // touchesBegan:withEvent: would have failed the recognizer. 
    UITouch *touch = [touches anyObject]; 

    // To rotate with one finger, we simulate a second finger. 
    // The second figure is on the opposite side of the virtual 
    // circle that represents the rotation gesture. 

    CDCircle *view = (CDCircle *) [self view]; 
    CGPoint center = CGPointMake(CGRectGetMidX([view bounds]), CGRectGetMidY([view bounds])); 
    CGPoint currentTouchPoint = [touch locationInView:view]; 
    CGPoint previousTouchPoint = [touch previousLocationInView:view]; 
    previousTouchDate = [NSDate date]; 
    CGFloat angleInRadians = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x); 

    CGFloat one = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x); 

    CGFloat two =atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);  
    currentTransformAngle = atan2f(view.transform.b, view.transform.a); 


    [self setRotation:angleInRadians]; 

답변

1

난 당신이 변수에 현재 angleInRadians를 저장하고, 새로운 각도가 현재보다 더 큰 (또는 작은) 경우에만 회전을 허용한다고 생각합니다.

+0

하지만이 값이 바뀌면 오른쪽으로 회전 할 때 sometines가 음수가되고 sometines가 음수가됩니다 ... 이해할 수 없습니다 – Aitul

관련 문제