views:

623

answers:

2

Hi there, 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 setAnimationDuration: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.

A: 

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

Tom Irving
Ok I did that:-(void)fadeLoop { [self fadeIn];}-(void)fadeIn { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2.0]; [UIView setAnimationDidStopSelector:@selector(fadeOut:finished:context:)]; [infoLbl setAlpha:1.0]; [UIView commitAnimations];}-(void)fadeOut:(NSString*)animationID finished:(BOOL)finished context:(void*)context { [UIView beginAnimations:nil context:context]; [UIView setAnimationDuration:2.0]; infoLbl.alpha = 0.0; [UIView commitAnimations];}now it doesn't fade-in nor fade-out
Oscar Peli
Set the animationDelegate of the first animation to self.
Tom Irving
+2  A: 
[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.

Manjunath
YES! Thanks! (I used the first one sample).
Oscar Peli