我想動畫UILabel
的文本,以便它顯示一個文本幾秒鐘,然後淡入默認文本。延遲UILabel中的文本之間的淡入淡出
我目前使用下面的代碼:
-(void)tapOnBalance:(id)sender{
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
cell.amountLabel.text = @"Hola!";
} completion:nil];
// Pause the function - act as a 'delay'
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:3]];
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
cell.amountLabel.text = @"Hallo!";
} completion:nil];
}
這工作,但[NSRunLoop currentRunLoop]
被暫停整個應用程序,3秒阻止一切。
如何擺脫主線程上的塊並仍然得到相同的結果?
您是否考慮過使用動畫方法的「延遲」參數? – 2014-11-02 19:41:46
是的,但它們不適用於'UILabels' – bdv 2014-11-02 19:42:09
不知道downvote,但(1)在這種情況下不必暫停主線程......利用完成塊並延遲。 (2)看看這個答案,以獲得如何正確執行這種UILabel轉換的幫助:http://stackoverflow.com/a/16367409/2274694 – 2014-11-02 19:54:43