开发者

UILabel fade-in fade-out question

开发者 https://www.devze.com 2022-12-25 17:38 出处:网络
I got the following code inside an NSTimer selector: [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2.0];

I got the following code inside an NSTimer selector:

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

[UIView beginAnimations:nil context:NULL];
[UIView set开发者_StackOverflow社区AnimationDuration:2.0];
[infoLbl setAlpha:1];
[UIView commitAnimations];

So I want to implement a simple fade-in/fade-out loop upon a UILabel (infoLbl).

Well, with this code I get only the fade-in step, since the UILabel suddenly disappear, then fades-in.

Some suggestion?

Thanks.


[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];

}

Insetad of this, if you are using NStimer Selecor then y dont u tryout changing color of the uilabel text? like:

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

Above method will enable you to fade in/out in a loop pretty easily.


Fade in first, setting an animationDidStopSelector: and inside the selector (see documentation for more information), tell it to fade out.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号