繁体   English   中英

如何禁用UIButton 3秒钟?

[英]How to disable a UIButton for 3 seconds?

大编辑:我完全是Obj-C和iOS开发的初学者。

当按下我的UIButton时,带有淡入的标签。此标签需要3秒钟才能淡入。如何在这3秒钟内禁用UIButton?

这是我正在尝试的:

[UIView animateWithDuration:3.0f animations:^{
    self.button.enabled = NO;
    self.quoteLabel.alpha = 1.0f;
    self.quoteLabel.text = self.quotes.randomQuote;
    self.labelForNumberOfTimesRead.text = [NSString stringWithFormat:@"+ %d",numberOfTimesRead ];

}];
self.button.enabled = YES;

但是它仅对“即时”禁用。

你可以这样简单地做

self.button.enabled = NO;
self.quoteLabel.text = self.quotes.randomQuote;
self.labelForNumberOfTimesRead.text = [NSString stringWithFormat:@"+ %d",numberOfTimesRead ];
    [UIView animateWithDuration:3 animations:^{
        self.quoteLabel.alpha = 1.0f;
        } completion:^(BOOL finished) {
            self.button.enabled = YES;
        }
         ];

目前尚不清楚您在使用labelForNumberOfTimesRead做些什么。 您是否也想让那个淡入淡出?

我认为您应该放置一些代码,以便我们可以更好地帮助您。 现在我要添加psudocode。您可以在此处使用NSTimer。

  1. 单击按钮添加[yourButton setEnable : NO]

  2. 动画完成后,添加[yourButton setEnable : YES]

  3. 如果您在获取动画完成事件方面遇到任何困难,那么您也可以使用NSTimer。

// Start by disabling the button
self.button.enabled = NO;

// This method will **queue** an animation but it won't start right away
[UIView animateWithDuration:3.0f animations:^{

    // Next animate anything you want
    self.quoteLabel.alpha = 1.0f;
    self.quoteLabel.text = self.quotes.randomQuote;
    self.labelForNumberOfTimesRead.text = [NSString stringWithFormat:@"+ %d",numberOfTimesRead ];

}
// Use completion block to re-enable button
completion:^(BOOL finished){
    self.button.enabled = YES;
}
];

// The following line is commented as it would be executed before the animation block!
// self.button.enabled = YES;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM