我想動畫計算向上計算digets的計數。文本是類似於You have driven for 0.0km
的UILabel,需要使用計數動畫將其更改爲You have driven for 143.6km
。有什麼辦法可以更新動畫?更新UILabel文本動畫
編輯 下面是我的一些當前的代碼,關於其他的動畫我已經有了:
if (animated)
{
[UIView beginAnimations:@"scaleAnimation" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:animationDuration];
}
[...]
// Amount pointer
float xForRedBar = redBarFrame.size.width + redBarFrame.origin.x;
CGRect pointerFrame = cell.amountBarPointer.frame;
pointerFrame.origin.x = (xForRedBar - (pointerFrame.size.width/2));
if (pointerFrame.origin.x < 12)
pointerFrame.origin.x = 12;
if (pointerFrame.origin.x >= (308 - (pointerFrame.size.width/2)))
pointerFrame.origin.x = 308 - pointerFrame.size.width;
[cell.amountBarPointer setFrame:pointerFrame];
// Amount bar
CGRect amountBarFrame = cell.amountBar.frame;
amountBarFrame.origin.x = 9+(((302 - amountBarFrame.size.width)/100)*self.procentCompleted);
[cell.amountBar setFrame:amountBarFrame];
// Amount info text
CGRect amountInfoFrame = cell.amountInfo.frame;
amountInfoFrame.origin.x = amountBarFrame.origin.x + 2;
[cell.amountInfo setFrame:amountInfoFrame];
// Amount text
[cell.amountInfo setText:[NSString stringWithFormat:NSLocalizedString(@"You have driven for %@km", nil), self.userAmount]];
[...]
if (self.procentCompleted == 0)
{
[cell.amountBar setAlpha:0];
[cell.amountBarPointer setAlpha:0];
[cell.amountInfo setAlpha:0];
}
else {
[cell.amountBar setAlpha:1];
[cell.amountBarPointer setAlpha:1];
[cell.amountInfo setAlpha:1];
}
if (animated)
{
[UIView commitAnimations];
}
在這裏你去:http://stackoverflow.com/a/6267259/1228534 – graver 2013-02-12 15:01:20
謝謝...但是,這並沒有解決我的問題。 – 2013-02-12 15:07:53
那麼你的問題是如何改變每個'x'毫秒的數字,直到它從值'a'變爲值'b'?答案就是使用'NSTimer',就像下面的@rdelmar建議的那樣。或者你的問題與任何兩個數字之間的變化的實際動畫有關嗎? – Mathew 2013-02-12 17:18:16