我使用CAKeyframeAnimation制作了一个水杯从空到满的动画。动画效果非常好。
我需要用对应于玻璃填充度的百分比来更新UILabel,即动画开始时它将显示为“0%”,结束时为“100%”。
关键帧动画运行5秒钟。我看不到更新此标签的好方法。我可以想到两种选择:
有一个更好的方法吗?
提前致谢
最佳答案
您可以使用NSTImer或dispatch_after()块按预定的时间间隔更新标签:
// assume an ivar "NSTimer *myTimer" and "int count", initially 0
// fires 20 times, so update is 0.05
myTimer = NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(updateLabel:) userInfo:nil repeats:YES
- (void)updateLabel:(NSTimer *)timer
{
++count;
if(count >= 20) {
[timer invalidate];
}
CGFloat percent += 0.05;
myLabel.text = [NSString stringWithFormat:...
}
关于ios - 如何将UILabel文本中的更改与相关动画同步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11967266/