gpt4 book ai didi

objective-c - 如何让 UILabel 文本在几秒后消失?

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:26 25 4
gpt4 key购买 nike

我的匹配纸牌游戏有一个 UILabe,上面写着“Good match!”例如,如果你有匹配项,我想在用消息通知用户后让它消失。

那是什么方法呢?我可以让它消失吗..?谢谢。

这是我的 updateUI 方法:

    -(void) updateUI {

for (UIButton *cardButton in self.cardButtons) {
Card *card = [self.game cardAtIndex:[self.cardButtons indexOfObject:cardButton]];
[cardButton setTitle:card.contents forState:UIControlStateSelected];
[cardButton setTitle:card.contents forState:UIControlStateSelected|UIControlStateDisabled];
cardButton.selected = card.isFaceUp;
cardButton.enabled = !card.unplayble;
if (card.unplayble) {
cardButton.alpha = 0.1;
}
self.scoreCounter.text = [NSString stringWithFormat:@"Score: %d", self.game.score];


if (self.game.notification) {
[UIView animateWithDuration:2 animations:^{
self.notificationLabel.text = [NSString stringWithFormat:@"%@", self.game.notification];
self.notificationLabel.alpha = 0;
}];
}

}
}

最佳答案

这将在两秒内淡出标签。将 animateWithDuration: 更改为您想要的长度

if (self.game.notification == nil) {
[UIView animateWithDuration:2 animations:^{
self.notificationLabel.alpha = 0;
}];
}

如果你想改变文本,试试这个(我现在不能测试,所以它可能不起作用)

[UIView animateWithDuration:2 animations:^{
self.notificationLabel.text = @"text you want to change it to";
}];

然后,当你想再次使用标签时,你必须将 self.notificationLabel.alpha 设置回 1。所以尝试

if (self.game.notification) {
self.notificationLabel.alpha = 1;
[UIView animateWithDuration:2 animations:^{
self.notificationLabel.text = [NSString stringWithFormat:@"%@", self.game.notification];
self.notificationLabel.alpha = 0;
}];
}

关于objective-c - 如何让 UILabel 文本在几秒后消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15350074/

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