动画后计算uiview的高度 [英] Calcul height of uiview after animating this one
问题描述
我有一个修改 UIView 约束的动画,我需要在动画之后知道这个 UIView 的大小,但在动画开始之前...
I have an animation who modify the constraint of an UIView and i need to know the size of this UIView after animate this, but before the animation begin...
当用户滚动 UITableView 时,我更新了黑色 UIView 的 heightConstraint,我需要更新 UIView 后的高度,因为我需要在函数 viewDidLayoutSubviews
中固定黄色 UIview 的高度.
When the user scroll the UITableView I update the heightConstraint of the black UIView, I need the height after update the UIView because i need in the function viewDidLayoutSubviews
to fixe the height of the Yellow UIview.
这是我用于动画 UIView 的代码:
this is the code I use for animate the 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 的高度?
So, the question is: How I can pre-calculate the height of the UIView after animating this ?
推荐答案
试试这个:
self.headerIsCollapsed = true
//create this property at instance level in your viewcontroller class
self.heightBeforeAnimation = self.heightProfileView.frame.size.height
self.heightProfilView.constant -= (self.view.bounds.height / 5)
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
self.imageUserProfil.layer.opacity = 0
}){ (isCompleted) in
//create this property at instance level in your viewcontroller class
self.heightAfterAnimation = self.heightProfileView.frame.size.height
}
并调用任何函数并使用包含动画视图前后高度值的两个变量的值.
and call whatever function and use the value of two variables containing value of height before and after animating your view.
这篇关于动画后计算uiview的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!