0
有人可以告訴我爲什麼這不是動畫嗎?我覺得代碼是完美的,但動畫功能不起作用。按鈕是從一邊跳到另一邊,但就像我說它不是動畫...我正在嘗試使用約束動畫我的解釦並且動畫不起作用
func moveResetButton(constraint : NSLayoutConstraint, isOffScreen : Bool) {
if isOffScreen {
//animate the button onto the screen
UIView.animate(withDuration: 3.0, delay: 0.0, options: .curveLinear, animations: {
constraint.constant += 120
}, completion: nil)
} else {
//animate the button off of the screen
UIView.animate(withDuration: 1.0, delay: 0.0, options: .curveLinear, animations: {
constraint.constant -= 120
}, completion: nil)
}
}
我已經給我的回答添加了評論。基本上,你正在改變動畫中的約束*。這是行不通的。您需要(1)更改約束,然後**(**)使變化生效。 – dfd
嘿。是的,我其實是想通了,現在就添加它。我在SO的前一個問題上發現它,並且它在Objective-C中。我不知道我是如何理解它,但它的工作。大聲笑感謝您的努力,但。我希望將來能聽到更多的消息。 :) – AdrianGutierrez