2012-10-16 20 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

但是,這個值的變化,當你向右旋轉時是正面的,有些負面的......我無法理解它 – Aitul