IOS webview的一些手势

  • 在weview上添加tap不好使
    解决:
    设置tap的代理,并实现
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
    返回yes,表示可以支持多个tap
  • 使webview的长按复制等操作失效
    解决一:
    for (UIGestureRecognizer *gesture in [[[webView subviews][0] subviews][0] gestureRecognizers]) {
    if ([gesture isKindOfClass:[UILongPressGestureRecognizer class]]) {
    [gesture removeTarget:nil action:nil];
    }
    }

解决二:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
for (UIGestureRecognizer *gesture in [[[webView subviews][0] subviews][0] gestureRecognizers]) {
if ([gesture isKindOfClass:[UILongPressGestureRecognizer class]]) {
[[[webView subviews][0] subviews][0] removeGestureRecognizer:gesture];
}
}
}
在didfinishload方法中添加 remove,因为:经测试webview load 数据后,会自动给webview的后台view上添加longpress手势。

你可能感兴趣的:(IOS webview的一些手势)