Search code examples
iosautolayout

How to resolve ambiguous layout?


I want an iPad layout that that has two panels side by side, to fill the width of the screen and both are as tall as the screen. My attempts have led to as follows

self.view addConstraints:
    @"|[_sidePanel(300)]-1.0-[_mainPanel]|"
    @"V:|[_sidePanel]|"
    @"V:|[_mainPanel]|"

Inside __sidePanel_ I'm trying to create more constraints on child views.

Note the _sidePanel view is a UIScrollView.

I want to stack 2 views on top of one another in the side panel.
So I add the following constraints to__sidePanel_.

_sidePanelView addConstraints:
    @"|[_top(300)]|"
    @"|[_bottom(300)]|"
    @"V:|[_top]-5.0-[_bottom]|"

It seems I need to specify the width for these two views in order to avoid ambiguity.

But I want the bottom view to fill the remaining space of __sidePanel_.

If I just pin __bottom_ to the bottom of __top_ (which gets a defined height at some point based on its contents) and to the bottom of its parent __sidePanel_, the __sidePanel_ and __bottom_ are both ambiguous; which makes sense i guess since the constraints are awfully similar (and which doesn't get avoided by adding the constraint for __bottom_ to the __sidePanel_ view as opposed to the topmost self.view).

If I hardcode a height for __bottom_, i resolve ambiguity but I don't want a defined height; i want it to fill remaining space in __sidePanel_.

Any suggestions on what I could try to resolve ambiguity but still achieve what I'm after?


Solution

  • In my case it came down to the fact that the view I was trying to have subviews constrain to its bounds was a UIScrollView, which wasn't happening. I since changed it to a UIView and voila my constraints work. And there you have it.