简体   繁体   中英

iOS UIStackView unable to simultaneously satisfy constraints if set hidden

I have a problem referring to an UIStackView . I created a StackView and added a few items bundled into another StackViews to it. Now I want to animate the inner StackViews with the hidden attribute to switch between different objects. For that I call StackView.hidden in code in ViewDidLoad for hiding the StackView with the items in it. 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. If I switch the spacing to 0, the problem disappears. 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. 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. I would suggest putting the UIStackView you wish to hide in another UIStackView with distribution set to fill not fill proportionally

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM