I have a table view with static cells. One cell contains a UITextView
and the heightForRowAtIndexPath:
is calculated dynamically so that the cell is always tall enough to accomodate the text (that part took some work under iOS 7, actually, as it's no longer possible to simply ask the textView for its contentSize
).
When I tap within the text view to start editing, the keyboard animates into place, the contentInsets on the tableView are automatically adjusted to account for this (ie, bottom inset of 216px for iPhone portrait orientation), the cursor / caret becomes visible, and then the table view scrolls to another location. It ends up looking like a bounce.
Here's a video of this in the simulator: https://www.dropbox.com/s/htdbb0t7985u6n4/textview-bounce.mov
Notice that for a second the caret is just above the keyboard. I've been logging the table view's contentOffset
and I can see it scroll to a nice value and then suddenly "turn around" and scroll back.
Oddly, if I turn on slow animations in the simulator the problem disappears; the contentOffset
reversal doesn't happen and things work as I expect (ie, iOS 6 behavior).
Here's the video with slow animations: https://www.dropbox.com/s/nhn7vspx86t4exb/textview-nobounce.mov
Implementation notes:
- The text view is pink and has AutoLayout constraints that keep it pinned to the cell at distance 0 (except left side, which is 10pts)
- I'm using
boundingRectWithSize:
to calculate the table view height, adjusting for lineFragmentPadding and any top/bottom insets. Seems to work. - I have set the textView to not be scrollable, but didn't notice anything different when
scrollEnabled
== YES - This is a table view controller and
automaticallyAdjustsScrollViewInsets
== YES
Try to adjust UITableView frame when keyboard appears. Call
[self attachKeyboardHelper]
in viewWillAppear and[self detachKeyboardHelper]
in viewWillDisappear.