我正在编写一个ap,当你按下按钮时,该按钮应该在0-10秒之间的随机时间内被禁用,之后,按钮再次变为活动状态。但是,当按钮被禁用时,如果用户点击,则点击似乎只是排队等待按钮被启用并且将处理点击。我将如何禁用和不排队用户点击?
-(void)buttonPressed{
NSLog(@"Button pressed!");
button.userInteractionEnabled=false;
sleep(rand()%10);
progLabel.text=@"button is enabled!";
button.userInteractionEnabled = true;
}
答案 0 :(得分:2)
你可以用它来代替sleep()func
[self performSelector:@selector(sleepMethood) withObject:nil afterDelay:0.5];
在pood中调用睡眠功能
-(void) sleepMethood
{
sleep(rand()%10);
}
或其他解决方法
-(void)buttonPressed{
NSLog(@"Button pressed!");
button.alpha=0.7;
button.enabled=NO;
[self performSelector:@selector(BtnEnblMethood) withObject:nil afterDelay:(rand()%10)];
progLabel.text=@"button is enabled!";
}
-(BtnEnblMethood)
{
button.alpha=1;
button.enabled=YES;
}
答案 1 :(得分:1)