这是我的观点的结构:垂直于底部视图的俯视图。两个视图之间存在约束,并且有一个X将视图的垂直距离设置为0。
我正在制作动画以移出顶视图(在顶部)。由于约束,底部视图应该自动向上移动。
但顶视图即将结束。底部视图仍然是固定的。
我做错了什么?
func hideTopSection() {
UIView.animate(withDuration: 0.5, delay: 0.0, options: [.curveEaseInOut], animations: {
self.topSectionView.center.y = -self.topSectionView.bounds.height
self.view.layoutIfNeeded()
}, completion: nil)
}
答案 0 :(得分:1)
框架布局无济于事,因为它不会强制定位相关元素,尝试自动布局,因此,当IBOutlet说topViewTopCon
func hideTopSection() {
self.topViewTopCon.constant = -1 * self.topSectionView.bounds.height
UIView.animate(withDuration: 0.5, delay: 0.0, options: [.curveEaseInOut], animations: {
self.view.layoutIfNeeded()
}, completion: nil)
}
答案 1 :(得分:1)
如果您使用Autolayout更改帧,位置,边界等没有任何效果,因为Autolayout将在下一个布局步骤中覆盖您的修改。您必须更改约束才能修改布局。在您的情况下:更改self.topSectionView
的顶部约束的常量。