【问题标题】:How to display a view when webview is touched continously for 10 sec?连续触摸 webview 10 秒时如何显示视图?
【发布时间】: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


【解决方案1】:

尝试类似:

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 秒。请记住,如果手指被拖动,则不再是长按..

【讨论】:

  • @Larsaronen : 有什么方法可以让我确定触摸点的坐标吗?
  • 是的,有 CGPoint tapLocation = [gestureRecognizer locationInView:self.webView];
  • @Larsaronen :谢谢我能够确定它。
猜你喜欢
  • 1970-01-01
  • 2013-11-22
  • 1970-01-01
  • 2013-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-09
  • 1970-01-01
相关资源
最近更新 更多