使用 UIGestureRecognizer 隐藏视图中的导航栏和工具栏,其中包含 UIWebView 和 UIImage
我正在使用 UIImageView、2xUIWebView 创建 UIViewController。
我试图用 UITapGestureRecognizer 隐藏 UINavigationBar 和 UIToolBar,没问题,但是当我在 ViewController 中添加时UIWebView 它停止工作。在“UIWebView youtube 播放器”中 - 我有从 youtube 播放视频的代码。当我触摸“白色区域”或 UIImageView 时,手势识别器可以工作,但是当我触摸 UIWebView 时,什么也没有发生。请帮助我修复它。谢谢
I'm creating a UIViewController with UIImageView, 2xUIWebView.
I'm trying to hide UINavigationBar and UIToolBar with UITapGestureRecognizer, It's no problem, but when i added in ViewController UIWebView it stop works. In "UIWebView youtube player" - I Have code which plays video from youtube. When I'm touching in "white area" or UIImageView- gesture recognizer works, but when I'm touching UIWebView - nothing happens. Help me please fix it. Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将手势识别器添加到父视图中,那么您就做错了。您应该将其附加到 webView。
而不是
If you are add gesture recognizer to the parent view than you are doing it wrong. You should attach it to the webView instead.
instead of
UIWebView由一些子视图组成,而子视图已经添加了一些手势识别器,所以如果你只是给UIWebView添加手势识别器,它不会被处理,因为视图树中更深的UIView会先处理手势。为了允许新添加的手势识别器和内置手势识别器同时处理,您应该采用 UIGestureRecognizerDelegate 协议来允许这样做。
有关一些详细信息,请参阅此博客:如何向 UIWebview 点击手势添加自定义流程
UIWebView consists of some subviews, and the subviews have already add some gesture recognizers, so if you just add gesture recognizer to UIWebView, it will not be processed, because the deeper UIView in the view tree will handle the gesture first. To allow both the new added gesture recognizer and the built-in gesture recognizer processed simultaneously, you should adopt the UIGestureRecognizerDelegate protocol to allow this.
for some detail information see this blog: How to Add Custom Process to UIWebview Tap Gestures