我想在視圖出現時動畫UILabel的值。爲此我創建了這個功能。動畫增量UILabel
private func animateIncrementUILabel(label: SpringLabel, labelValue: Int, animationPeriod: Float?)
{
animationPeriod != nil ? animationPeriod! : 40
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
for (var i = 0; i < labelValue; i++)
{
usleep(UInt32(animationPeriod!)/100 * 1000000)
dispatch_async(dispatch_get_main_queue(), {
label.text = String(i)
})
}
})
}
但在我的viewDidAppear方法調用這個時候像
animateIncrementUILabel(counterLabelOne, labelValue: 20, animationPeriod: 40.0)
它顯示在標籤馬上沒有「動畫incremention」的值。
我在這裏做錯了什麼?
刪除這些調度塊和使用的NSTimer .Schdule活動,而不是睡眠 –