如果UIButton
已被禁用[myButton setEnabled:NO];
是否可以使用仍然有效的觸摸偵聽器?iOS向上觸摸禁用按鈕
我曾嘗試:
[self addTarget:self action:@selector(myButtonTUI:) forControlEvents:UIControlStateDisabled];
,但無濟於事。
如果UIButton
已被禁用[myButton setEnabled:NO];
是否可以使用仍然有效的觸摸偵聽器?iOS向上觸摸禁用按鈕
我曾嘗試:
[self addTarget:self action:@selector(myButtonTUI:) forControlEvents:UIControlStateDisabled];
,但無濟於事。
回答你的問題是沒有
enabled
A Boolean value that determines whether the receiver is enabled.
@property(nonatomic, getter=isEnabled) BOOL enabled
Discussion
Specify YES to make the control enabled; otherwise, specify NO to make it disabled.
The default value is YES. If the enabled state is NO, the control ignores touch
events and subclasses may draw differently.
可以模擬這樣的功能?是。
而不是禁用該按鈕,請檢查功能是否應在按鈕動作選擇器上觸發。你甚至可以改變圖像,使其看起來被禁用。這樣按鈕仍然會收到觸摸事件,並且如果符合正確的條件,您可以觸發所需的功能。
UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myButtonHit)];
[self.myButtonView addGestureRecognizer:gesture];
出於某種原因,它似乎沒有附接時的工作:
這可以通過在相同尺寸的UIView
包裹UIButton
並附加敲擊手勢識別器到父視圖來實現手勢識別器到UIButton
本身,這本來是最好的解決方案。
有一個比這更好的解決方案。我們不能只將另一個手勢識別器附加到按鈕上嗎? – devios1 2013-09-03 21:43:09
爲了記錄,我通過將按鈕放入「UIView」並將一個手勢識別器附加到「UIView」來實現此目的。由於某些原因,將它直接連接到按鈕時不起作用。 – devios1 2013-09-03 22:53:00
您將遇到無障礙方面的問題。 – rshev 2016-11-24 11:40:55