我写了一个名为updateLabel的函数来随时间计算我收集的硬币。我使用NSTimer调用该函数以获得计数效果。
在iOS 8中,一切都运行良好,但是当我在iOS 7.1中调用该函数时,我的标签就变成空白...如果我打印Label.text,我会得到正确的数字,但它只是不显示。甚至声音“coinSound”也可以正常播放。
感谢您的帮助。
在iOS 8中,一切都运行良好,但是当我在iOS 7.1中调用该函数时,我的标签就变成空白...如果我打印Label.text,我会得到正确的数字,但它只是不显示。甚至声音“coinSound”也可以正常播放。
scoreLabel = SKLabelNode()
scoreLabel.text = "0"
self.addChild(scoreLabel) // shows up and works with "0"
self.timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self.self, selector: "updateLabel", userInfo: nil, repeats: true)
func updateLabel() {
var score:Int = coinsCollected
var current:Int = self.scoreLabel.text.toInt()!
if (current < score) {
current += 1
scoreLabel.text = String(current)
println("current: \(current) , labelText: \(scoreLabel.text)")
self.runAction(coinSound)
} else {
timer.invalidate()
}
}
感谢您的帮助。