[英]Use UIStackview in xib, Hiden and show subview issue
Use UIStackview
in xib, Hiden and show subview issue I have two subviews in my StackView
, A subview is hidden, B subview is unhidden,A is on the top of B;Set the status of A to show,But A is covered by B. 在xib中使用UIStackview
,隐藏并显示子视图问题我的StackView
有两个子视图,一个子视图被隐藏,B子视图StackView
隐藏,A在B的顶部;设置A的状态为show,但是A被B覆盖。
only occurs in the Xcode10.1 and ios12.0++. 仅发生在Xcode10.1和ios12.0 ++中。
I wondered why it is happening only to you..!! 我想知道为什么它只发生在你身上。 However, I've tried the same way that what you specified in the question and got the result perfectly. 但是,我尝试了与您在问题中指定的方法相同的方法,并完美地获得了结果。
Code: 码:
override func viewDidLoad() {
super.viewDidLoad()
let myStackView = UIStackView()
myStackView.axis = .vertical
myStackView.alignment = .center
myStackView.distribution = .fillEqually
myStackView.spacing = 8
view.addSubview(myStackView)
let redView = UIView()
redView.backgroundColor = UIColor.red
redView.widthAnchor.constraint(equalToConstant: 125.0).isActive = true
redView.heightAnchor.constraint(equalToConstant: 50).isActive = true
let greenView = UIView()
greenView.backgroundColor = UIColor.green
greenView.widthAnchor.constraint(equalToConstant: 125.0).isActive = true
greenView.heightAnchor.constraint(equalToConstant: 50).isActive = true
myStackView.addArrangedSubview(redView)
myStackView.addArrangedSubview(greenView)
myStackView.translatesAutoresizingMaskIntoConstraints = false
myStackView.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 0.0).isActive = true
myStackView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 0.0).isActive = true
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
redView.isHidden = true
}
DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
redView.isHidden = false
}
}
Screenshots: 截图:
On viewDidLoad
& and after 4 seconds of viewDidLoad
上viewDidLoad
与4秒后viewDidLoad
after 2 seconds of viewDidLoad
2秒后viewDidLoad
I found the reason, because the height constraint of the A view is not effective when the constant property of the heightLayoutConstraint is changed from 0 to the actual height of 100. These are all done in the main thread. 我找到了原因,因为当heightLayoutConstraint的constant属性从0更改为实际高度100时,A视图的高度约束无效。这些都在主线程中完成。
UICollectionReusableView *customView;//Xib init
NSLayoutConstraint *customHeightConstraint;
//change constant
customHeightConstraint.constant = height;
[customView updateConstraints];
But I looked at the effects and properties in the debug view hierarchy and found that the customView is still the initial value of 0. 但是我查看了调试视图层次结构中的效果和属性,发现customView仍然是初始值0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.