Best way to make text blink on iPhone OS?

I want my text box to blink (like an old LCD clock).

Right now I'm calling a lot of NSTimers and selectors that wait, change alpha, wait, and then change it. Even so, it looks very bad, and I think I need to put NSTimer to gradually change the alpha, but from what I heard, they are not intended for things of such accuracy.

My thoughts are that there must be a way to do this much better than the way I implement it now. It looks like a hack.

+4
source share
4 answers

Using an animation delegate can make it less "hacked":

[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; [myLabel setAlpha:0.0]; [UIView commitAnimations]; 

And then you can restart the didStopSelector animation:

 - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [self displayLabel]; } 

Depending on the animation id, you can perform different actions, etc. Using the UIView setAnimationDelay may also come in handy.

UIView also has a setDuration call for animations:

 [UIView setAnimationDuration:0.1]; 

If you are creating for iOS4, check out the documentation, as you should use block-based animation calls, not based on these delegates.

+7
source

you can set the alpha file with the spell as

to hide animation 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 that anyone can animate and create a blinking ribbon ........

+5
source

I would use NSTimer, but instead of messing with alpha channels, I would either not draw text (if this is possible even with Apple with a very limited set of SDK features), or if this is not possible, you can always draw something on top he (like a rectangle).

Using this approach when drawing something over text will give better performance. While some (well, most) consider this an ugly hack, let me just say this: "If everything looks right, it's right."

+1
source

NSTimers and changing alpha is a perfectly acceptable way to do this - this is definitely what I am doing. If you are having problems, maybe a sample code can help us see where the problem is?

0
source

Source: https://habr.com/ru/post/1314775/


All Articles