2010-04-25 64 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]

这种方法的主要优点是您不必制作自定义视图子类