手势识别与UIWebView [英] Gesture recognition with UIWebView

查看:126
本文介绍了手势识别与UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我正在建立的应用程式中设定了一些手势识别功能。其中一种手势是单指单击,隐藏屏幕顶部的工具栏。除了一件事情,工作得很好:一个链接上的点击也会导致工具栏消失。



可以检测到一个点击,链接?我可以通过查看水龙头发生的地方,只采取行动,如果它没有发生在html链接上这样做?这是可能的,一个指针,如何确定是否链接被点击将是有帮助的。



Per Octys建议,我试图将UIWebView包装在UIView内。我使用的接口生成器,所以我在层次结构中插入一个视图,并使UIWebView的新的UIView的孩子。现在的层次结构如下:





我在视图控制器中为视图添加了一个IBOutlet,并在界面生成器中将它链接起来。



我改变手势识别器设置看起来像这样:

  UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action: @selector(handleSingleTap :)]; 
singleTap.numberOfTouchesRequired = 1;
singleTap.delegate = self;
[self.UIWebViewContainer addGestureRecognizer:singleTap];
[singleTap release];

此代码位于viewDidLoad中。



像以前一样,代码正确地看到单个手指单击,但是UIWebView中的链接上的点击也导致工具栏消失。



任何人都有建议吗?



谢谢。



Chris



感谢
Chris

UIView 容器中尝试包装 UIWebView 在容器视图上设置您的手势识别器。未被 UIWebView 处理的触摸事件将在视图层次结构中向上传递,并由您的容器视图拦截,假设它实现了适当的处理程序(并且这些处理程序应该实现隐藏工具栏的代码...)。


I have set up some gesture recognition in an app that I'm building. One of the gestures is a single finger single tap, which hides the toolbar at the top of the screen. Works great except for one thing: a tap on a link causes the toolbar to go away, too.

Is it possible to detect a tap that was not a tap on a link? Could I do this by seeing where the tap occurred, and only take action if it didn't occur on an html link? Is this is possible, a pointer to how to determine if a link was tapped would be helpful.

Per Octys suggestion, I did attempt to wrap the UIWebView inside a UIView. I'm using interface builder, so I inserted a view in the hierarchy, and made the UIWebView a "child" of the new UIView. The hierarchy looks like this now:

I added an IBOutlet for the view in my view controller, and linked it up in interface builder.

I changed the gesture recognizer setup to look like this:

UITapGestureRecognizer* singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTap:)];
singleTap.numberOfTouchesRequired=1;
singleTap.delegate=self;
[self.UIWebViewContainer addGestureRecognizer:singleTap];
[singleTap release];

This code resides in viewDidLoad.

As before, the code correctly sees a single finger single tap, but a tap on a link in the UIWebView also causes the toolbar to go away. I only want the toolbar to go away if a link was NOT tapped.

Anyone have any suggestions?

Thank you.

Chris

Thanks Chris

解决方案

Try wrapping your UIWebView in a UIView container and set your gesture recognizers on the container view. Touch events that are not handled by the UIWebView will be passed up the view hierarchy and be intercepted by your container view, assuming it implements the appropriate handlers (and it is these handlers that should implement the code for hiding the toolbars...).

这篇关于手势识别与UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆