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

前端之家收集整理的这篇文章主要介绍了用于UIScrollView的iOS5 UITapRecognizer干扰按钮.怎么修?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在UIScrollView中的UIView中有一堆UIButtons.我正在尝试在滚动视图中添加点按识别器.点击识别器会触发,但现在我的按钮都没有工作.

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

解决方法

将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 Class Reference

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

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.

原文链接:https://www.f2er.com/iOS/334990.html

猜你在找的iOS相关文章