我正在寻找一种有效的方法来为使用 UILabel 的计时器制作动画。计时器的动画应该类似于旧标签上从上方出现的较高数字。
我知道如何制作动画,但是我如何确保它花费一秒钟的确切时间?(应该是准确的)。
目前,我正在使用当前 NSDate 每 0.5 秒调用一次的 NSTimer 更新我的标签。这是必要的,以便用户可以关闭应用程序并且计时器"继续"。
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self
selector:@selector(refreshTimeLabel:)
userInfo:nil repeats:YES];
是否有任何建议如何提供精确到秒计数的 UILabel,该 UILabel 随动画递增?
您可以在.h文件中获取一个整数变量
int seconds;
并在视图中在 .m 文件中加载
seconds = 0;
并在其下方启动计时器
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self
selector:@selector(refreshTimeLabel:)
userInfo:nil repeats:YES];
-(void)refreshTimeLabel:(id)sender
{
seconds++;
lblDisplay.text = [NSString stringWithFormat:@"%d",seconds];
}
你说你知道如何做动画,所以只需使用你的动画在上述方法上设置标签,祝你好运:)