2010-04-25 38 views

回答

4

如果你不針對3.2+:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    if ([touches count] == 2) { 
     //etc 
    } 
} 
+0

謝謝eman!解決了我的問題! – 2010-04-26 00:26:39

2

multiTouchEnabled屬性設置爲YES

0

如果您的要求允許,請使用UITapGestureRecognizer。整個

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; 

跟蹤,看看有多少倒是有,他們是否移動比你的點擊/拖動閾值;否則,實現自定義的UIView以下UIResponder方法。您必須實施全部四種方法。

10

如果你可以針對OS 3.2或以上,你可以使用一個UITapGestureRecognizer。它非常易於使用:只需配置它並將其附加到視圖即可。當執行手勢時,它將觸發gestureRecognizer目標的動作。

例子:

UITapGestureRecognizer * r = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewWasDoubleTapped:)]; 
[r setNumberOfTapsRequired:2]; 
[[self view] addGestureRecognizer:r]; 
[r release]; 

然後你只實現一個- (void) viewWasDoubleTapped:(id)sender方法,當[self view]得到雙擊操作時,將被調用。

編輯

我才意識到你可能會談論檢測用兩個手指一個水龍頭。如果是這種情況,你可以做

[r setNumberOfTouchesRequired:2]

這種方法的主要優點是您不必製作自定義視圖子類