は、私が2秒で0%〜50%Objective-CでUILabelが徐々に表示する数値を徐々に増やすには?
UILabel *percentage.text = [NSString stringWithFormat:@" %ld%%", 0];
からUILabelで表示される数を増やしたいと言います。ここで
percentage.text = [NSString stringWithFormat:@" %ld%%", 0]
は、私はNSTimerを使用しようとしたものです:
self.percent = 0;
self.timer = [NSTimer timerWithTimeInterval:0.04
target:self
selector:@selector(updateLabel)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
//updateLabel
- (void)updateLabel{
self.percentage.text = [NSString stringWithFormat:@" %ld%%", self.percent++];
if (self.percent > 50) {
[self.timer invalidate];
self.timer = nil;
}
}
をしかし、UIは確か際に、非常にぎくしゃく見えるすべての変更が積層されているように、すべてのルックスで、滑らかではない、時には適用されますがありません確実に2秒以上かかる。これは0.04秒が短すぎるためですか?
良い方法がありますか?
申し訳ありませんが、問題はないのthats –