我正在玩Swift,专门用于在Apple Watch上创建应用程序。我试图在手表的用户界面中设置一系列按钮的动画。
我已经编写了一个函数,我将WKInterfaceButton传递给了我希望它通过将Alpha更改为0并返回1来使按钮闪烁。 我创建了一个串行队列,并且理解传递给它的任何块都将按顺序执行,因此将按钮调暗的指令放在队列中,然后将指令放回队列,如果我保留,则为下一个按钮的指令调用函数。
很明显,我错过了一些基本的东西,因为屏幕上没有任何反应,任何帮助都会感激不尽!
let alphaTimer = 1.00
var serialQueue = dispatch_queue_create("com.apollodev", DISPATCH_QUEUE_SERIAL)
private func animateButton(button: WKInterfaceButton) {
dispatch_async(serialQueue) {
self.animateWithDuration(self.alphaTimer, animations: { () -> Void in
button.setAlpha(0)
})
}
dispatch_async(serialQueue) {
self.animateWithDuration(self.alphaTimer, animations: { () -> Void in
button.setAlpha(1)
})
}