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.
精彩评论