与UIGestureRecognizer一起侦听UITouch事件 [英] Listening to UITouch event along with UIGestureRecognizer
问题描述
我正在创建自定义UIView并在其上添加UITapGestureRecognizer。我有一个处理程序的点击手势。但同时我想让我的UIView听touchesBegan& touchesEnded方法。我实现了gestureRecognizer:shouldReceiveTouch:方法,但是touchesBegan / touchesEnded方法不会被调用。任何线索为什么?
I am creating a custom UIView and adding a UITapGestureRecognizer on it. I have a handler for the tap gesture. But at the same time I want my UIView to listen to touchesBegan & touchesEnded methods. I have implemented gestureRecognizer:shouldReceiveTouch: method also but touchesBegan/touchesEnded methods does not get called. Any clue why?
在自定义UIView内
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)iGestureRecognizer shouldReceiveTouch:(UITouch *)iTouch {
return YES;
}
在我的视图控制器 b
$ b
Inside my view controller
MyCustomView aCustomView = [[[MyCustomView alloc] init] autorelease];
UIGestureRecognizer *myGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[aCustomView addGestureRecognizer:myGestureRecognizer];
[myGestureRecognizer release];
推荐答案
您需要设置 cancelsTouchesInView
(可能
delaysTouchesBegan
和 delaysTouchesEnded
)至 code>用于手势识别器。手势识别器的默认行为是避免它和视图两者都处理触摸。这些设置可让您调整此行为。
You need to set cancelsTouchesInView
(and likely delaysTouchesBegan
and delaysTouchesEnded
) to NO
for the gesture recognizer. The default behavior of a gesture recognizer is to avoid having both it and the view process the touch. These settings let you fine-tune that behavior.
这篇关于与UIGestureRecognizer一起侦听UITouch事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!