我有一个UILabe用于我的匹配纸牌游戏,它写的是“好搭配!”例如,如果你有一个匹配,我想在通知用户消息后让它消失。
这是什么方法?我可以让它流逝吗?谢谢。
这是我的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;
}];
}
}
}
答案 0 :(得分:3)
这会使标签在两秒钟内消失。将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;
}];
}
答案 1 :(得分:-2)
我不认为这是可能的。很可能,您需要在Interface Builder中使用NSView替换UILabel,并使用其中包含的绘图功能以透明的方式绘制文本。