【发布时间】:2010-09-17 07:33:25
【问题描述】:
我正在 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;
}
请检查一下,是我弄错了吗?
【问题讨论】:
-
看起来不错,您必须将
添加到您的 .h,并设置 longPressGestureRecognizer.delegate = self..
标签: iphone ipad uiwebview touch