用于 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 干扰按钮.怎么修?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么

基础教程推荐