用于UIScrollView的iOS5 UITapRecognizer干扰按钮。怎么修? [英] iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?

查看:106
本文介绍了用于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 property cancelsTouchesInView 改为NO。

Set the UIGestureRecognizer property cancelsTouchesInView to 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 Class Reference


A影响触摸是否是在识别手势时传递给视图的
的布尔值。

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

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