gpt4 book ai didi

iphone - UIView 动画 block 不工作

转载 作者:行者123 更新时间:2023-11-28 18:45:19 26 4
gpt4 key购买 nike

我试图让我的计时器在游戏还剩不到 10 秒时闪烁红色。由于某种原因,动画无法正常工作。 timeLabel 只是变成白色并保持这种状态。这是我正在使用的代码:

if (timeLeft <= 9 && timeLeft > 0) {
timeLabel.textColor = [UIColor redColor];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelegate:self];
timeLabel.textColor = [UIColor whiteColor];
[UIView commitAnimations];
}

奇怪的是,我在另一个运行良好的应用程序中使用了完全相同的代码块。也许我类的某个地方有另一个动画干扰了这个动画?

最佳答案

文本颜色不是动画属性。您可以尝试使用 CATextLayer改为执行此操作。

另一种选择是在白色 UILabel 的顶部放置一个带有红色文本的相同 UILabel,然后将其从透明淡化为不透明,然后再淡化为不透明。看起来像这样:

if (timeLeft <= 9 && timeLeft > 0) {
redTimeLabel.alpha = 0;
[UIView animateWithDuration:1
animations:^{
redTimeLabel.alpha = 1;
}
completion:^(BOOL finished){
redTimeLabel.alpha = 0;
}];
}

关于iphone - UIView 动画 block 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5044581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com