我在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.