【发布时间】:2017-04-27 02:03:28
【问题描述】:
谁能告诉我为什么这不是动画?我觉得代码都很完美,但动画功能不起作用。按钮会立即从一边跳到另一边,但就像我说的那样它没有动画......
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) 更改约束,然后然后 (2) 为更改设置动画。
-
嘿。是的,我实际上已经弄清楚并添加了它。我在关于 SO 的前一个问题上找到了它,它在 Objective-c 中。我不知道我是如何理解它的,但它确实有效。大声笑感谢您的努力。我希望将来能听到更多来自你的消息。 :)
标签: swift animation uibutton constraints