连续触摸webview 10秒后如何显示视图?

时间:2010-09-17 07:33:25

标签: iphone ipad uiwebview touch

我正在webview中显示pub或pdf文件。但是我无法检测到webview上的触摸。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
当我触摸pdf或pub文件的任何文本时,会调用

上面的方法。如何检测显示pdf或pub文件的webview上的点击。

这是我的代码:

- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://dblog.com.au"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPressGestureRecognizer.minimumPressDuration = 6.0;
[self.webView addGestureRecognizer:longPressGestureRecognizer];
[longPressGestureRecognizer release];

}

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"Long press detected");
 }

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

请检查一下,我犯了什么错误吗?

1 个答案:

答案 0 :(得分:4)

尝试类似:

UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPressGestureRecognizer.minimumPressDuration = 10.0;
[self.webView addGestureRecognizer:longPressGestureRecognizer];
[longPressGestureRecognizer release];

然后:

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"Long press detected");
}

编辑:

添加:

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

但按下同一个地方10秒是很长时间...长按的默认值是0.4秒。请记住,如果手指被拖动,则不再需要长按..