Sen*_*zle 4 iphone methods objective-c nstimer ios
我希望我的文本框闪烁(就像旧的LCD时钟一样).
现在,我正在呼叫无数的NSTimers和选择器等待,更改alpha,等待,然后将其更改回来.即便如此,它看起来非常糟糕,我想我必须使用NSTimer来逐渐改变alpha,但是从我听到它们并不意味着那些精确的东西.
我的想法是,必须有一种方法比我目前正在实施它的方式做得更好.感觉就像黑客.
使用动画委托可能会减少"hacky":
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[myLabel setAlpha:0.0];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
然后你可以让你的didStopSelector重新启动动画:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[self displayLabel];
}
Run Code Online (Sandbox Code Playgroud)
根据animationID,您可以采取不同的操作,等等.使用UIView的setAnimationDelay也可以派上用场.
UIView还有一个动画的setDuration调用:
[UIView setAnimationDuration:0.1];
Run Code Online (Sandbox Code Playgroud)
如果您正在为iOS4构建,请检查文档,因为您应该使用基于块的动画调用而不是基于委托的动画调用.
小智 5
你可以设置标签的alpha与annimation一样
用动画隐藏标签
[UIView animateWithDuration:0.2 delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{
lblDistance.alpha=0;
} completion:^(BOOL finished) {
if (finished) {
}
}];
Run Code Online (Sandbox Code Playgroud)
用动画来表现
[UIView animateWithDuration:0.2 delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{
lblDistance.alpha=1;
} completion:^(BOOL finished) {
if (finished) {
}
}];
Run Code Online (Sandbox Code Playgroud)
这是任何人都可以动画制作闪亮标签的最佳方式........
| 归档时间: |
|
| 查看次数: |
3081 次 |
| 最近记录: |