UILabel淡出淡出问题

Osc*_*eli 2 iphone animation fade uilabel

我在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];
Run Code Online (Sandbox Code Playgroud)

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

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

一些建议?

谢谢.

Man*_*ath 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];

}
Run Code Online (Sandbox Code Playgroud)

如果您正在使用NStimer Selecor,那么你是否尝试改变uilabel文本的颜色?喜欢:

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

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