title: Expanding UITextView inside a Stack View with scrolling enabled
body: <p>I am trying to achieve something with Auto Layout and Stackview. I have a Vertical Stackview with a UIView, UITextView, and UIView in it as shown below. </p>
  
  <p><a href="https://i.stack.imgur.com/1CaQv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1CaQv.png" alt="enter image description here"></a></p>
  
  <p>I have checked out the previous answers here but couldn't find a clean solution to achieve this.</p>
  
  <p>The <code>UITextView</code> is editable and must expand as the user types in it - for this I have disabled the scroll for the <code>UITextView</code> in the IB. I also have a height constraint set on the UITextView set to "Greater than or equal to" 10 and number of lines set to 0, so that the <code>UITextView</code> takes the intrinsic height at run time while the user types. I also want the expansion of the UITextView to continue until the <code>UIStackView</code> bottom edge reaches the Keypad accessory's top edge. I have been somewhat able to achieve the expanding <code>UITextView</code> part with my stack view pinned to the top, trailing, and leading edges of the Superview but I keep getting an error that the <code>stackview needs Y position or height</code> which is understandable but if I give it a fixed height or bottom constraint then the UITextView simply won't expand.</p>
  
  <p>I also am not sure how to stop the expansion of the UITextView when it reaches the top edge of the Keyboard accessory view.</p>
  
  <p>The code that I have so far is </p>
  
  <pre><code>let allowedHeight = self.view.frame.height - (self.keyboardHeight! + self.accessory.frame.height)
  </code></pre>
  
  <p>Basically find the allowed height in the view frame by subtracting the keyboardheight+Accessory view height. This calculation happens correctly. Next I do this (inside <code>textViewDidChange</code>) in hopes that just enabling/disabling the scroll on the <code>UITextView</code> would work but it clearly doens't since the whole text view then weirdly jumps up and down with every key stroke. </p>
  
  <pre><code>func textViewDidChange(_ textView: UITextView) {
     if stackView.frame.height &gt;= allowedHeight{
              textView.isScrollEnabled = true
          }
  
     if stackView.frame.height &lt; allowedHeight{
              textView.isScrollEnabled = false
          }
  }
  </code></pre>
  
  <p>What is the best way to achieve what I am looking to do?</p>