UILabel淡出淡出问题

时间:2010-04-07 09:45:07

标签: iphone animation uilabel fade

我在NSTimer选择器中获得了以下代码:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[infoLbl setAlpha:0];
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[infoLbl setAlpha:1];
[UIView commitAnimations];

所以我想在UILabel(infoLbl)上实现一个简单的淡入/淡出循环。

好吧,有了这段代码,我只得到了淡入淡出的步骤,因为UILabel突然消失,然后淡入。

有什么建议吗?

感谢。

2 个答案:

答案 0 :(得分:10)

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDuration:2.0];
[infoLbl setAlpha:0];
[UIView commitAnimations];

//This delegate is called after the completion of Animation.
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationDuration:2.0];
  [infoLbl setAlpha:1];
  [UIView commitAnimations];

}

如果你使用的是NStimer Selecor,那么你不尝试改变uilabel文字的颜色吗?像:

-(void)timerSelector
{
    if([textLabel textColor] == [UIColor blackColor])
    {
        [textLabel setTextColor:[UIColor grayColor]];   
    }
    else
    {
        [textLabel setTextColor:[UIColor blackColor]];  
    }
}

上面的方法可以让你很容易地在循环中淡入/淡出。

答案 1 :(得分:0)

首先淡入,设置animationDidStopSelector:并在选择器内部(有关详细信息,请参阅文档),告诉它淡出。

相关问题