title: UITextView content offset changes after setting frame
body: <p>I'm building a view that's very similar to the messages app - I have a subview at the bottom of the page with a <code>UITextView</code> in it and as the user types and reaches the end of the line the text view as well as the view containing it should expand upward.</p>
  
  <p>The way I have it working is that in the <code>textViewDidChange:</code> method I call my layout function, and that does</p>
  
  <pre><code>CGFloat textViewWidth = 200;
  CGFloat textViewHeight = [self.textView sizeThatFits:CGSizeMake(textViewWidth, 2000)].height;
  [self resizeParentWithTextViewSize:CGSizeMake(textViewWidth, textViewHeight)];
  
  // And then the resize parent method eventually calls
  textView.frame = CGRectMake(10, 10, textViewWidth, textViewHeight);
  </code></pre>
  
  <p>The problem is that when typing at the end of line and the view expands, I end up with an arbitrary <code>contentOffset.y</code> of something like 10.5 on the text view so the text is all shifted up to the top of the view. Weirdly, it's alternating on every other line, so expanding the first time leaves the y content offset shifted up, then at the next line it's close to zero, then back to 10.5 on the next line, etc.  (not sure if that's helpful or just a strange artifact of my values). I can set it back to zero afterwards but it looks terrible because there's a brief flash where the text has the offset value and then it gets shifted back to the middle.</p>
  
  <p>I've read that it's usually better to use content insets for scroll views rather than changing the frame, but I don't get how to do that because I do need to change the frame size as well.</p>
  
  <p>How can I resize the <code>UITextView</code> without this happening? I think I can get by with setting the text view not to be scrollable and that fixes the issue, but I'd like to understand what's going on.</p>