用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么

iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
本文介绍了用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIScrollView 中的 UIView 中有一堆 UIButton.我正在尝试将点击识别器添加到滚动视图.点击识别器触发,但现在我的按钮都不起作用.

I have a bunch of UIButtons within a UIView within a UIScrollView. I'm trying to add a tap recognizer to the scroll view. The tap recognizer fires, but now none of my buttons work.

我知道在 iOS5 中,UIScrollView 可以在完成后以某种方式将触摸事件向下传递到控件层次结构.任何人都可以帮我弄清楚如何做到这一点?

I know that in iOS5, UIScrollView can somehow pass a touch event down to the control hierarchy after being done with it. Anyone can help me figure out how to do this?

推荐答案

设置UIGestureRecognizer属性cancelsTouchesInView为NO.

UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self 
                                                                                             action:@selector(singleTap:)];
singleTapGestureRecognizer.numberOfTapsRequired = 1;
singleTapGestureRecognizer.enabled = YES;
singleTapGestureRecognizer.cancelsTouchesInView = NO;
[tapableView addGestureRecognizer:singleTapGestureRecognizer];
[singleTapGestureRecognizer release];

来自 UIGestureRecognizer 类参考

影响是否触摸的布尔值当手势被识别时传递到视图.

A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.

当此属性为 YES(默认值)并且接收者识别其手势,该手势的触摸是未交付的未交付到视图和之前交付的触摸通过 touchesCancelled:withEvent: 消息被取消发送到风景.如果手势识别器无法识别其手势,或者如果此属性的值为 NO,视图接收所有触摸多点触控序列.

When this property is YES (the default) and the receiver recognizes its gesture, the touches of that gesture that are pending are not delivered to the view and previously delivered touches are cancelled through a touchesCancelled:withEvent: message sent to the view. If a gesture recognizer doesn’t recognize its gesture or if the value of this property is NO, the view receives all touches in the multi-touch sequence.

这篇关于用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

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)瞄准较新的版本)