2011-06-17 87 views
2

有沒有辦法檢測用戶所做的旋轉是順時針還是逆時針直接?iphone開發 - UIRotationGestureRecognizer(順時針和逆時針檢測)?

我搜索了,但無法找到答案!

我的代碼如下所示:

UIGestureRecognizer *recognizer; 
recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(spin)]; 
[self.rotating addGestureRecognizer:recognizer]; 
[recognizer release]; 

回答

4

rotation屬性會告訴你在弧度rotation。負值表示旋轉是順時針的,正值表示逆時針旋轉。

例子:

UIGestureRecognizer *recognizer; 
recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(spin:)]; // <-- Note the colon after the method name 
[self.rotating addGestureRecognizer:recognizer]; 
[recognizer release]; 

- (void)spin:(UIGestureRecognizer *)gestureRecognizer { 
    CGFloat rotation = gestureRecognizer.rotation; 
    if (rotation < 0) { 
     // clockwise 
    } else { 
     // counter-clockwise 
    } 
} 
+0

非常感謝您! –

+1

它實際上是另一種方式。 > 0順時針,而<0是反時鐘。 – Roger

相關問題