動畫幀的大小利用NSAnimationContext.runAnimationGroup(_:_:)
。然而,由於預期的NSButton
,除非我動畫NSAnimationContext不爲NSButton
動畫效果的幀大小後面加一個明確的幀大小變化爲NSImageView
如預期的NSImageView以下作品這是行不通的。它被移動到原點,並調整爲200×200:
NSAnimationContext.runAnimationGroup({(let context) -> Void in
context.duration = 2.0
// Get the animator for an NSImageView
let a = self.theImage.animator()
// Move and resize the NSImageView
a.frame = NSRect(x: 0, y: 0, width: 200, height: 200)
}) {
print("Animation done")
}
動畫幀大小NSButton
與NSButton執行相同的情況下,該按鈕將移動但無法調整:
NSAnimationContext.runAnimationGroup({(let context) -> Void in
context.duration = 2.0
// Get the animator for an NSButton
let a = self.button.animator()
// Move and resize the NSImageView
a.frame = NSRect(x: 0, y: 0, width: 200, height: 200)
}) {
print("Animation done")
}
但是,如果我將下面的代碼行添加到最後,所有的動畫後德,它按預期工作!
self.button.frame = NSRect(x: 0, y: 0, width: 200, height: 200)
爲NSButton
最後,工作列表:
NSAnimationContext.runAnimationGroup({(let context) -> Void in
context.duration = 2.0
// Get the animator for an NSButton
let a = self.button.animator()
// Move and resize the NSImageView
a.frame = NSRect(x: 0, y: 0, width: 200, height: 200)
}) {
print("Animation done")
}
self.button.frame = NSRect(x: 0, y: 0, width: 200, height: 200)
我不是在尋找一個禮物馬在這裏嘴,但爲什麼這需要NSButton我不明白,或甚至是什麼使其工作。任何人都可以解釋爲什麼明確設定後NSButton
的框架動畫代碼使動畫工作?