嵌套UIStackViews破碎约束 [英] Nested UIStackViews Broken Constraints
问题描述
我有一个复杂的视图层次结构,建于Interface Builder中,嵌套UIStackViews。我得到不可满足的约束的告示每次我隐藏一些我内心stackviews的时间。我跟踪它到这一点:
I have a complex view hierarchy, built in Interface Builder, with nested UIStackViews. I get "unsatisfiable constraints" notices every time I hide some of my inner stackviews. I've tracked it down to this:
(
"<NSLayoutConstraint:0x1396632d0 'UISV-canvas-connection' UIStackView:0x1392c5020.top == UILabel:0x13960cd30'Also available on iBooks'.top>",
"<NSLayoutConstraint:0x139663470 'UISV-canvas-connection' V:[UIButton:0x139554f80]-(0)-| (Names: '|':UIStackView:0x1392c5020 )>",
"<NSLayoutConstraint:0x139552350 'UISV-hiding' V:[UIStackView:0x1392c5020(0)]>",
"<NSLayoutConstraint:0x139663890 'UISV-spacing' V:[UILabel:0x13960cd30'Also available on iBooks']-(8)-[UIButton:0x139554f80]>"
)
具体而言, UISV间距
约束:隐藏当UIStackView其高约束得到一个0不变,但似乎与内stackview的间距约束冲突:它要求我的标签和按钮,这是不可调和的隐藏约束等约束崩溃。
Specifically, the UISV-spacing
constraint: when hiding a UIStackView its high constraint gets a 0 constant, but that seems to clash with the inner stackview's spacing constraint: it requires 8 points between my Label and Button, which is irreconcilable with the hiding constraint and so the constraints crash.
有没有办法解决?我试过躲在递归隐藏堆栈视图的所有内部StackViews,但导致在内容浮起了屏幕的怪动画,并导致严重的FPS下降到开机,而仍然没有解决问题。
Is there a way around this? I've tried recursively hiding all the inner StackViews of the hidden stack view, but that results in strange animations where content floats up out of the screen, and causes severe FPS drops to boot, while still not fixing the problem.
推荐答案
在理想情况下,我们可以只设置 UISV间距
约束到一个较低值的优先级,但有似乎没有任何办法做到这一点。 :)
Ideally we could just set the priority of the UISV-spacing
constraint to a lower value, but there doesn't appear to be any way to do that. :)
我有成功的隐藏之前设置的嵌套堆栈意见为0 间隔
属性,使得它再次显示后恢复到应有的价值。
I am having success setting the spacing
property of the nested stack views to 0 before hiding, and restoring to the proper value after making it visible again.
我觉得嵌套堆栈意见递归这样做是可行的。你可以在间距
属性的原始值存储在一个字典并在以后恢复它。
I think doing this recursively on nested stack views would work. You could store the original value of the spacing
property in a dictionary and restore it later.
我的项目只有嵌套一个水平,所以我不能确定这是否会导致FPS的问题。只要你不动画在间距的变化,我不认为它会造成太多的一击。
My project only has a single level of nesting, so I am unsure if this would result in FPS problems. As long as you don't animate the changes in spacing, I don't think it would create too much of a hit.
这篇关于嵌套UIStackViews破碎约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!