如何禁用UIButton并禁用touchEvent响应程序?

时间:2012-08-07 08:26:19

标签: objective-c ios uikit uibutton

我有IBOutlet UIButton。它启用时不会响应touchesBegan:withEvent:。但是当我设置[button setEnabled:NO]并点击直到它所在的位置时,它会转到touchesBegan:withEvent:

如何停用UIButton,并停用touchEvent responder? 我曾尝试过[button setEnabled:NO][button setUserInteractionEnabled:YES],但没有尝试过。

3 个答案:

答案 0 :(得分:2)

你试过吗?

[button setEnabled:NO];

[button setUserInteractionEnabled:NO]

答案 1 :(得分:0)

for disable touchesBegan:withEvent你可以使用

 self.view.userInteractionEnabled = NO; 

因为这个方法用于uiview(和uiimage的子类化的其他类)。当您单击按钮,调用按钮处理程序(而不是touchesBegan,touchMove)时,按钮是UIControl的子类。

答案 2 :(得分:0)

如果按钮被禁用。以下代码对您有好处。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{   
    UITouch *touch = [touches anyObject];

    if(CGRectContainsPoint(button.frame, [touch locationInView:self.view]))
        return;

   //do stuff
}
相关问题