【发布时间】:2025-12-29 06:15:12
【问题描述】:
我有一个动画修改了 UIView 的约束,我需要知道这个 UIView 在动画之后但在动画开始之前的大小......
当用户滚动 UITableView 时,我更新了黑色 UIView 的 heightConstraint,我需要更新 UIView 后的高度,因为我需要在函数 viewDidLayoutSubviews 中修复黄色 UIview 的高度。
这是我用来为 UIView 设置动画的代码:
self.headerIsCollapsed = true
self.heightProfilView.constant -= (self.view.bounds.height / 5)
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
self.imageUserProfil.layer.opacity = 0
})
我需要这里的值:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
heightTopBar.constant = // here i need the height of the UIView after animating this
}
所以,问题是:如何在动画后预先计算 UIView 的高度?
【问题讨论】:
-
自动布局会在纵断面高度降低后自动拉伸黄色视图,所以去掉黄色高度会自动拉伸
-
动画后预先计算是什么意思?这没有意义。也许你之前的意思?
-
是的,谢谢。我了解了约束,并且更好地理解了它是如何工作的。我的问题解决了