0

I am attempting pretty much the same thing as the OP of this question in Xcode7.

My end goal is to have a vertical StackView with two child views: one that occupies 70% of the parent's height, and one that occupies the remaining 30%.

I followed the instructions in the post I linked. I selected the child view (which is a GMSMapView) and the parent StackView and checked the equal heights box in the Pin constraints menu. That worked just fine and dandy. However, when I edited that constraint from the GMSMapView's size inspector and changed the multiplier to .7, suddenly I get a conflicting constraints error!

Here is a picture of the scene I am working on right now: The scene with the stack view

And here is a picture of the error:

The conflicting constraints!

Does anyone know how to resolve these conflicts? I tried turning off Autoresize Subviews but I am not sure that worked since I can't delete some of the constraints displayed in the error message.

Community
  • 1
  • 1
scottysseus
  • 1,922
  • 3
  • 25
  • 50

1 Answers1

0

The height of a UIStackView is based off of the size of its subviews (Unless your using UIStackViewDistributionFillEqually).

The first two conflicting constraints evaluate to this

Stack View.height = View.height
Map View.height = 0.7 x Stack View.height

But since the UIStackView bases its height on its subviews, there is essentially a third constraint.

Stack View.height = Map View.height

All of these constraints can not exist together since they conflict.


There are two options I can think of.

Remove the UIStackView. Since it only contains one view, you aren't getting any benefit from using it and it's only complicating things.

If that's not an option, you will need to remove some constraints so that you aren't constraining the UIStackView to a specific height.

Craig Siemens
  • 12,942
  • 1
  • 34
  • 51
  • I'd like to add a third option (which is actually what fixed my problem): add in a second child of the `StackView` and set it to fill the remaining `.3 x Stack View.height`. Your statement `But since the UIStackView bases its height on its subviews, there is essentially a third constraint` is what hinted to me that the solution was to simply fill the entirety of the `StackView`'s height to make the conflicting constraints agree. Since this was my plan from the beginning, everything worked out. – scottysseus Nov 26 '15 at 20:11
  • I'd still say removing the `UIStackView` is a better solution since it's doing nothing more than a `UIView` would be doing. – Craig Siemens Nov 26 '15 at 21:21