[英]iOS UIStackView unable to simultaneously satisfy constraints if set hidden
I have a problem referring to an UIStackView
. 我在引用UIStackView
问题。 I created a StackView and added a few items bundled into another StackViews to it. 我创建了一个StackView并添加了一些捆绑到另一个StackViews中的项目。 Now I want to animate the inner StackViews with the hidden attribute to switch between different objects. 现在,我想使用隐藏属性为内部StackView设置动画,以在不同对象之间切换。 For that I call StackView.hidden
in code in ViewDidLoad
for hiding the StackView with the items in it. 为此,我呼吁StackView.hidden
在代码ViewDidLoad
隐藏的StackView在它的项目。 The codes seems to work in Simulator, but it throws an error: 代码似乎在模拟器中工作,但它会抛出一个错误:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x7fd29d00b460 'UISV-canvas-connection' UIStackView:0x7fd29acdb3b0.top == UIStackView:0x7fd29acdc120.top>",
"<NSLayoutConstraint:0x7fd29d00b5a0 'UISV-canvas-connection' V:[UISlider:0x7fd29accb620]-(0)-| (Names: '|':UIStackView:0x7fd29acdb3b0 )>",
"<NSLayoutConstraint:0x7fd29d00f8d0 'UISV-hiding' V:[UIStackView:0x7fd29acdb3b0(0)]>",
"<NSLayoutConstraint:0x7fd29d00b9a0 'UISV-spacing' V:[UIStackView:0x7fd29acdc120]-(10)-[UISlider:0x7fd29accb620]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fd29d00b9a0 'UISV-spacing' V:[UIStackView:0x7fd29acdc120]-(10)-[UISlider:0x7fd29accb620]>
I identified the problem inside the inner StackView to be the Spacing. 我将内部StackView中的问题确定为Spacing。 If I switch the spacing to 0, the problem disappears. 如果我将间距切换为0,问题就会消失。 But I don't want to miss the spacing. 但我不想错过间距。 I think another option is to hide every single object inside the inner StackView, but that's an enormous effort and it's more simple to hide the StackView. 我认为另一种选择是隐藏内部StackView中的每个对象,但这是一项巨大的工作,并且隐藏StackView更加简单。 Is there any idea how to fix that problem? 有什么想法解决这个问题吗?
Thanks for your help! 谢谢你的帮助!
Just for future reference: I have had this happen when I wanted to hide a UIStackView. 仅供将来参考:当我想要隐藏UIStackView时,我已经发生了这种情况。 I would suggest putting the UIStackView you wish to hide in another UIStackView with distribution set to fill not fill proportionally 我建议你把UIStackView隐藏在另一个UIStackView中,其分布设置为填充不按比例填充
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.