自从将我的项目升级到 swift 3 后,我的自动布局约束动画无法正常工作;更具体地说,它们是捕捉到新位置而不是动画。
UIView.animate(withDuration: 0.1,
delay: 0.1,
options: UIViewAnimationOptions.curveEaseIn,
animations: { () -> Void in
constraint.constant = ButtonAnimationValues.YPosition.DefaultOut()
self.layoutIfNeeded()
}, completion: { (finished) -> Void in
// ....
})
我知道他们添加了 UIViewPropertyAnimator
类,但我还没有尝试过。
最佳答案
我对 swift 3 的最新更新也遇到了这个问题。
确切地说,无论何时您想要为 View 设置动画,您实际上都在该 View 的父 View 上调用了 layoutIfNeeded。
试试这个:
UIView.animate(withDuration: 0.1,
delay: 0.1,
options: UIViewAnimationOptions.curveEaseIn,
animations: { () -> Void in
constraint.constant = ButtonAnimationValues.YPosition.DefaultOut()
self.superview?.layoutIfNeeded()
}, completion: { (finished) -> Void in
// ....
})
在过去,他们似乎对能够重新布局您想要动画的 View 一直很宽容。但是在文档中,您确实应该在 super View 中调用 layoutIfNeeded。
关于ios - Swift 3 UIView 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39489925/