title: Autoresize UIPopoverController using autolayout
body: <p>I'm trying to use autolayout to automatically resize my popover to fit it's contents. I have fixed popover width but to compute height i rely on <code>systemLayoutSizeFittingSize:</code> passing my predefined width and zero height e.g. CGSizeMake(190, 0).</p>
  
  <pre><code>ContentController* controller = [ContentController new];
  CGSize preferredSize = [controller.view systemLayoutSizeFittingSize:CGSizeMake(190, 0)];
  controller.preferredContentSize = preferredSize;
  UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:controller];
  //popover presentation.
  </code></pre>
  
  <p>So far, so well, my current ContentController view hierarchy is something like (setup in the Interface Builder):</p>
  
  <pre><code>UILabel - multiline header (dynamically resized)
     |
  UIImage with fixed width / height (static size)
     |
  UILabel - multiline body (dynamically resized)
  </code></pre>
  
  <p>Thus, i just plug in my header / body text, call <code>systemLayoutSizeFittingSize</code> and it returns valid size that fits all the content of the view.</p>
  
  <p><img src="https://i.stack.imgur.com/7yuC1.png" alt="Dynamic height label with short text"></p>
  
  <p><img src="https://i.stack.imgur.com/L1x51.png" alt="Dynamic height label with long text"></p>
  
  <p>The problem arises when i try to put my body label inside UIScrollView. (Both in the IB and in code).
  <img src="https://i.stack.imgur.com/45abB.png" alt="Dynamic height is broken with scrollview"></p>
  
  <p>From now on, <code>systemLayoutSizeFittingSize</code> will not take body label height into account and will return height for header + image.
  I've setup all the constraints in the IB to support Pure Autolayout approach.</p>
  
  <p>I've checked scrollview's content size - it is indeed equals to body label's intrinsic size, but scroll view's frame is squashed into 0.<br>
  I've checked and tried to reset label's maxPreferredLayoutWidth to the width of the content view, but it doesn't seems to affect anything.</p>
  
  <p>I've set translatesAutoresizingMaskIntoConstraints on every view to NO, but it has no effect.
  I've set hugging / compression resistance priorities of both label and it's scrollview to 1000, but no luck. Setting them on the container view doesn't work either.</p>
  
  <p>Here are screenshots of my IB view setup:</p>
  
  <p><img src="https://i.stack.imgur.com/eZecW.png" alt="Label setup"></p>
  
  <p><img src="https://i.stack.imgur.com/ZRLqZ.png" alt="ScrollView with inner label setu"></p>
  
  <p>My guess that is is somehow related to popover hosting views and their autolayout constraints, but i'm not sure.</p>
  
  <p>I'm updating my labels via simple</p>
  
  <pre><code>_textContainerHeaderLabel.text = headerText;
  _textContainerBodyTextLabel.text = bodyText;
  
  
  [self.view setNeedsUpdateConstraints];
  [self.view layoutSubviews];
  </code></pre>
  
  <p>So, the main question - how do i compute view's optimal fitting size via autolayout when it has UIScrollViews in it?</p>