在iPhone OS中让文本闪烁的最佳方法是什么? [英] Best method to get text to blink in iPhone OS?
问题描述
我希望我的文本框闪烁(就像旧的LCD时钟一样)。
I want my text box to blink (like the old LCD clocks).
现在,我正在呼叫无数的NSTimers和选择器等待,改变阿尔法,等待,然后改回来。即便如此,它看起来非常糟糕,而且我认为我必须使用NSTimer来逐渐改变alpha,但是从我听到它们并不意味着那些精确的东西。
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.
推荐答案
使用动画委托可能会减少hacky:
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];
然后你可以让你的didStopSelector重新启动动画:
And then you can have your didStopSelector restart the animation:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[self displayLabel];
}
根据animationID,您可以采取不同的操作,等等。使用UIView的setAnimationDelay也可以派上用场。
Depending on the animationID, you could take different actions, etc. Using UIView's setAnimationDelay might come in handy as well.
UIView还有动画的setDuration调用:
UIView also has a setDuration call for animations:
[UIView setAnimationDuration:0.1];
如果您正在为iOS4构建,请检查文档,因为您应该使用基于块的动画调用比这些基于代表的那些。
If you are building for iOS4, check the documentation since you should be using block-based animation calls rather than these delegate based ones.
这篇关于在iPhone OS中让文本闪烁的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!