如何在5秒内显示图形时禁用按钮?

问题描述:

如何禁用从被压一个UIButton ... 而我显示5秒的图形?如何在5秒内显示图形时禁用按钮?

self.view.userInteractionEnabled = NO; // if you need the whole view disabled 
    //self.btn.enabled = NO; //if you need button only disabled 

    [UIView animateWithDuration:3.0f animations:^ 
     { 
      // your graphical changes 
      [(UILabel*)addLbl[1] setBackgroundColor:[UIColor redColor]]; 
     } 
    completion:^ (BOOL finished) 
     { 

      self.view.userInteractionEnabled = YES; 
      //self.button.enabled = YES; 
      [(UILabel*)addLbl[1] setBackgroundColor:[UIColor whiteColor]]; 
     } 
    ]; 

可以使用延时方法:

//make your animations and graphical changes.. 
//.... 

self.myButton.enabled = NO; 
[self performSelector:@selector(changeButton) withObject:nil afterDelay:5.0]; //this will happen after 5 seconds 

-(void)changeButton { 
self.myButton.enabled = YES; 
} 

// EDITED。试试这个

self.view.userInteractionEnabled = NO; // if you need the whole view disabled 

[UIView animateWithDuration:3.0f animations:^ { 
    [(UILabel*)addLbl[1] setBackgroundColor:[UIColor redColor]]; 
} completion:^ (BOOL finished) { 
[UIView animateWithDuration:2.0f animations:^ { 
    [(UILabel*)addLbl[1] setBackgroundColor:[UIColor whiteColor]]; 
} completion:^ (BOOL hasFinished) { 
    self.view.userInteractionEnabled = YES; 
}]; 
}]; 
+0

的代码段后,我把另一个图形,但是,执行将不会显示临时图形,当我把在该代码段 – jdl

+0

如果您需要在一行几动画序列,像头后其他图形:门打开;第二:一个男人走过门 - 然后尝试把你的其他动画放在第一个动画的完成块内。让我知道,如果这听起来很清楚。 – Eugene

+0

我这样做,并且该块之后......结果是,临时图形从未显示 – jdl