2

我正在寻找一种有效的方法来为使用 UILabel 的 Timer 设置动画。计时器的动画应该类似于旧标签上从上方出现的更高数字。

我知道如何制作动画,但我怎样才能确保它需要一秒钟的确切时间?(应该是准确的)。

目前,我正在使用当前 NSDate 每 0.5 秒调用一次的 NSTimer 更新我的标签。这是必要的,以便用户可以关闭应用程序并且计时器“继续”。

self.timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self 
                                                selector:@selector(refreshTimeLabel:) 
                                                userInfo:nil repeats:YES];

是否有任何建议如何提供精确到秒计数的 UILabel,它随着动画的增加而增加?

4

1 回答 1

2

您可以在 .h 文件中取一个整数变量

int seconds;

并在 .m 文件中的 viewDidLoad

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];
}

你说你知道怎么做动画,所以只要用你的动画在上面的方法上设置标签,祝你好运:)

于 2013-09-09T04:33:15.773 回答