大编辑:我完全是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;

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

===============>>#1 票数:2 已采纳

你可以这样简单地做

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做些什么。 您是否也想让那个淡入淡出?

===============>>#2 票数:1

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

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

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

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

===============>>#3 票数:0

// 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;

  ask by espitia translate from so

未解决问题?本站智能推荐: