我有一个基于约束的高度动画。但是,当动画开始时,它将 View 的中心作为 anchor 而不是顶部。
我希望它动画为固定顶部并从底部收缩。
对不起,我的英语不是母语人士。
我的观点主播:
top: superview
left: superview
right: superview
bottom: nil
// current height constant 200
view.height.constant = 0
UIView.animation(withDuration: 0.2, animations: {
view.layoutIfNeded()
}}
最佳答案
尝试代替你的观点:
superView.layoutIfNeeded()
这将布局 subview 并且您的动画应该可以工作。
所以替换
// current height constant 200
view.height.constant = 0
UIView.animation(withDuration: 0.2, animations: {
view.layoutIfNeded()
}
与
// current height constant 200
yourView.height.constant = 0
UIView.animation(withDuration: 0.2, animations: {
yourViewSuperview.layoutIfNeded()
}
请参阅 layoutIfNeeded() 苹果文档:[1]https://developer.apple.com/documentation/uikit/uiview/1622507-layoutifneeded
关于ios - 自动布局动画以中心为 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45344067/