0

As shown in the image, we have a couple of problems in a storyboard concerning to auto layouts, we have, let's say, StackView1 and StackView2. The problem I'm currently having is that StackView 1 and StackView 2 need to resize based on the content (height >= 100 and bottom space) that's why it is in red, because StackView 1 need constraints for: Y position (same for StackView2).

We have a couple of bugs because of that, and I wanted to do it rightly. As the question above says,

  1. How can I avoid these constraint errors?
  2. or do I need to completely refactor this part of the project?
  3. Which options do I have in that case?
  4. Which is the most used approach in this case?

Storyboard image

This is a xib I create for each "device" we have, so I don't know the height of the StackView 1 Xib image

Jalil
  • 1,025
  • 11
  • 29
  • What kind of view you are holding within you stack views? A stack view can determine its height only if its children have an `intrinsicContentSize`. – Eilon Oct 28 '19 at 18:00
  • I forgot to mention that the views inside fit perfectly and the stackviews resize just fine also. But of course there is something wrong if the constraints are in red. Inside `Stackview 1` I have a xib with a title label and a collection view. Inside `Stackview 2` I have a series of buttons that show you more info. – Jalil Oct 28 '19 at 18:07
  • It looks like sv1 can't calculate it's height, which is causing knock-on height errors throughout the view. Check you have top-to-bottom definite vertical constraints for the content of sv1. Without seeing the "internals" of the SVs this is just informed guesswork though :) – flanker Oct 28 '19 at 18:27
  • The problem is likely within the collection view in the first stack view. A collection view does not have an intrinsic content size by default, therefore the stack view cannot infer its size. Here is a solution to add an intrinsic size for your collection view: https://stackoverflow.com/a/54115679/4127258 – Eilon Oct 28 '19 at 18:29
  • @Eilon should I delete the height constraint after that? – Jalil Oct 28 '19 at 18:31
  • @flanker what do you mean? Could you refrase that please? – Jalil Oct 28 '19 at 18:38
  • @Jalil the point I was trying to make was that it appears all the errors seem to stem from the top stackview not being able to work out its internal height (the vertical red bar). Without that, all the other elements can't work out their vertical height either. Therefore check that all of the top stackview's views have a definitive height, either through an intrinsic height or a heigh constraint. It's hard to be specific without seeing the layout. Also if the stackView is just loading a single .xib (as I think you're previous comment implies) you'd probably be better off with just a UIView. – flanker Oct 29 '19 at 10:41
  • @flanker I updated my question with the xib, to show you a little bit more of what I'm doing – Jalil Oct 30 '19 at 22:55
  • @Jalil the earlier comment suggests there is only one xib in stackview1. Is this the case? – flanker Oct 31 '19 at 00:51
  • @flanker if you mean like, type of xib, yes there is only one type, but sometimes I instantiate a couple of the same but with different information – Jalil Oct 31 '19 at 04:31

0 Answers0