如何解决Swift iOS14动画约束
我正在尝试为视图的底部约束设置动画,以使其向上滑动。
这是我正在做的,但是它会立即跳到新位置,并且不会滑动:
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
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。