I want my text box to blink (like the old LCD clocks).
Right now, I'm calling a myriad of NSTimers and selectors that wait, change the alpha, wait, then change it back. Even with this, it looks really bad, and I'm thinking I have to put an NSTimer to gradually change the alpha, but from what I hear they are not meant for things of that precision.
My thoughts are there must be a way to do this a lot better than how I am currently implementing it. It feels like hack.
Using an animation delegate might make it less "hacky":
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[myLabel setAlpha:0.0];
[UIView commitAnimations];
And then you can have your didStopSelector restart the animation:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[self displayLabel];
}
Depending on the animationID, you could take different actions, etc. Using UIView's setAnimationDelay might come in handy as well.
UIView also has a setDuration call for animations:
[UIView setAnimationDuration:0.1];
If you are building for iOS4, check the documentation since you should be using block-based animation calls rather than these delegate based ones.
you can set the alpha of the lable with annimation just like
to hide lable with animation
[UIView animateWithDuration:0.2 delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{
lblDistance.alpha=0;
} completion:^(BOOL finished) {
if (finished) {
}
}];
to show lable with animation
[UIView animateWithDuration:0.2 delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{
lblDistance.alpha=1;
} completion:^(BOOL finished) {
if (finished) {
}
}];
this is the best way anyone can animate and create a blinking lable........
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With