I’d like to scroll my UITableView up when the keyboard is displayed so the textfields are not covered by the keyboard. I know how to scroll the tableView and the contentInset etc. I’m having trouble calculating the distance to scroll.
I have the keyboard dimensions (from UIKeyboardDidShowNotification). However I’m having trouble obtaining a useful origin value for the textfield that’s being edited. The origin of the UITextField passed to textFieldDidBeginEditing isn’t helpful: the value is the same regardless of the textField that’s being edited. textField.superview.origin isn’t helpful either.
How can I obtain a useful value for the origin of the textField that’s being edited?
I’ll use this value along with the keyboard height to determine the distance to scroll.
Personally what I think is best is to change the frame of the table view so that it’s not hidden at all by the keyboard (you can look at the keyboard frame and change the table view frame based on that). Then scroll the table view using
scrollToRowAtIndexPath:atScrollPosition:animated:so that the cell is visible.That way
UITableViewhandles what the actual content offset should be for you.