我有一个标签,每 5 秒取一个不同的值(字符串值:“blue”、“pink”、“green”、“orange”)
我想警告用户标签将在 1 秒前更改。例如,在标签取另一个值之前,标签的背景颜色应为红色 1 秒。
每5秒调用一次颜色变化函数的代码
let timerFunc: NSTimer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: Selector("colorChange"), userInfo: nil, repeats: true)
随机改变标签值的代码
func colorChange() {
let minRandomValue: UInt = 0
let maxRandomValue: UInt = 4
var numberRandom: UInt = UInt()
numberRandom = UInt(arc4random()) % (maxRandomValue - minRandomValue)
switch numberRandom {
case 0: couleur.text = "Blue";
case 1: couleur.text = "Green";
case 2: couleur.text = "Orange";
case 3: couleur.text = "Pink";
default: println("value problem")
}
}
稍后我会将 5 秒计时器延迟设为随机。谢谢。 Xcode 6.4, SDK 8.0
尝试以下...
1) 创建一个SKNode,2)创建一个红色的矩形SKSpriteNode并将其添加到SKNode,3)创建一个SKLabelNode并添加到SKNode中,4) 对自己运行以下操作
let changeColorWaitChangeBackground = SKAction.sequence([
SKAction.runBlock(self.changeColor),
SKAction.waitForDuration(4, withRange:2),
SKAction.runBlock(self.changeAlpha),
SKAction.waitForDuration(1),
])
在changeColor()中,设置颜色字符串,设置红色SKSpriteNode的alpha为0.0。
在changeAlpha()中,设置红色SKSpriteNode的alpha为1.0。
Tôi là một lập trình viên xuất sắc, rất giỏi!