ScrollView 手势识别器吃掉所有的触摸事件

ScrollView gesture recognizer eating all touch events(ScrollView 手势识别器吃掉所有的触摸事件)
本文介绍了ScrollView 手势识别器吃掉所有的触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIScrollView,我添加了一个点击手势识别器来显示/隐藏一些 UI 覆盖,使用:

I have a UIScrollView to which I added a single tap gesture recognizer to show/hide some UI overlay using:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[scrollView addGestureRecognizer:singleTap];

和:

- (void)handleTap:(UITapGestureRecognizer *)sender {
    // report click to UI changer
}

我在 UIScrollView 的底部添加了一个简易表格视图.一切正常(水平和垂直滚动),但问题是点击只能被手势识别器识别(上图),而不是简单的表格视图.如果我删除注册手势侦听器的行,一切正常,表格视图会通知自己点击.

I added an easy table view to the bottom of the UIScrollView. Everything works right (scrolling both horizontally and vertically) but the problem is that taps are recognized only by the gesture recognizer (above), but not by the easy table view. If I remove The line that registers the gesture listener, everything works fine, the table view notices taps on itself.

就好像手势识别器函数吃掉"了表格视图上的点击事件,而不是向下传播它们.

It's as if the gesture recognizer function "eats" the tap events on the table view and doesn't propagate them downward.

感谢任何帮助

推荐答案

这应该可以解决您的问题.
检测 UIScrollView 上的触摸事件 AND在 UIView 的组件上[放置在 UIScrollView 内]
这个想法是告诉手势识别器不要吞噬触摸事件.为此,您需要将 singleTap 的 cancelsTouchesInView 属性设置为 NO,默认为 YES.

This should solve your problem.
Detect touch event on UIScrollView AND on UIView's components [which is placed inside UIScrollView]
The idea is to tell the gesture recognizer to not swallow up the touch events. To do this you need to set singleTap's cancelsTouchesInView property to NO, which is YES by default.

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
singleTap.cancelsTouchesInView = NO;
[scrollView addGestureRecognizer:singleTap]; 

这篇关于ScrollView 手势识别器吃掉所有的触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)