如何在UIWebView上的长按手势上创建Tap事件?

时间:2012-11-07 00:48:54

标签: iphone ios ipad cocoa-touch uiwebview

我在UIWebView添加了长按手势。但我希望UIWebView能够在识别出我的长按之前处理标准的Tap事件。 (两个手势应该在Long Tap上处理 - 一个简单的Tap和我的Long Tap)。怎么做?

我认为需要在UIWebView上将Tap事件发送到TouchBegin。这是对的吗?

2 个答案:

答案 0 :(得分:2)

正确的代码:

- (void)viewDidLoad {
    UILongPressGestureRecognizer* gesture = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)] autorelease];
    gesture.delegate = self;
    [myWebView addGestureRecognizer:gesture];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

答案 1 :(得分:1)

请参阅本节UIGestureRecognizerDelegate

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html

你发现当2个手势同时工作时会调用它。

gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: