Swift iOS14 动画约束
Swift iOS14 Animate Constraints
我正在尝试为视图的底部约束设置动画,使其向上滑动。
这就是我正在做的,但它只是立即跳到新位置,它不会滑动:
UIView.animate(withDuration: 0.4) {
self.pickerBottomConstraint.constant += 300
self.agePicker.setNeedsLayout()
self.agePicker.layoutIfNeeded()
}
有谁知道如何在 iOS14 中设置动画约束?
你需要
self.pickerBottomConstraint.constant += 300 // this should be outside of animate
UIView.animate(withDuration: 0.4) {
self.view.layoutIfNeeded() // this should be called for at least the direct parent of the animated picker
}
我正在尝试为视图的底部约束设置动画,使其向上滑动。
这就是我正在做的,但它只是立即跳到新位置,它不会滑动:
UIView.animate(withDuration: 0.4) {
self.pickerBottomConstraint.constant += 300
self.agePicker.setNeedsLayout()
self.agePicker.layoutIfNeeded()
}
有谁知道如何在 iOS14 中设置动画约束?
你需要
self.pickerBottomConstraint.constant += 300 // this should be outside of animate
UIView.animate(withDuration: 0.4) {
self.view.layoutIfNeeded() // this should be called for at least the direct parent of the animated picker
}