dav*_*Mac 8 cocoa-touch uibutton ios
我有一种情况,用户将触摸UIButton,虽然他们可能已经触摸它,我需要能够取消它或导致它失败.
我曾尝试使用button.enabled和userInteractionEnabled,但两者都没有动态.两者都必须在触摸开始之前设置.
我可以在触摸后触摸时使按钮失效吗?
您需要为按钮注册两个操作,一个用于触摸,一个用于触摸.触摸下来,您可以决定是否要取消; 并在触摸时,写下按钮按下的实际逻辑.
[button addTarget:self action:@selector(touchDown:) forControlEvents:UIControlEventTouchDown];
- (IBAction)touchDown:(id)sender
{
UIButton *b = (UIButton*)sender;
// Call this if you wish to cancel the event tracking
[b cancelTrackingWithEvent:nil];
}
Run Code Online (Sandbox Code Playgroud)
供参考,请参阅in 的文档-cancelTrackingWithEvent:
UIControl
.
归档时间: |
|
查看次数: |
5571 次 |
最近记录: |