問題描述
我在 UIScrollView
中的 UIView
中有一堆 UIButton
.我正在嘗試將點擊識別器添加到滾動視圖.點擊識別器觸發(fā),但現(xiàn)在我的按鈕都不起作用.
I have a bunch of UIButton
s 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
可以在完成后以某種方式將觸摸事件向下傳遞到控件層次結(jié)構(gòu).任何人都可以幫我弄清楚如何做到這一點?
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?
推薦答案
設(shè)置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 類參考
影響是否觸摸的布爾值當(dāng)手勢被識別時傳遞到視圖.
A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.
當(dāng)此屬性為 YES(默認值)并且接收者識別其手勢,該手勢的觸摸是未交付的未交付到視圖和之前交付的觸摸通過 touchesCancelled:withEvent: 消息被取消發(fā)送到風(fēng)景.如果手勢識別器無法識別其手勢,或者如果此屬性的值為 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.
這篇關(guān)于用于 UIScrollView 的 iOS5 UITapRecognizer 干擾按鈕.怎么修?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!