I’m trying to move the content up when the keyboard appears. This is the content which is a simple login form.
Please note that these are not UITextField
s. Its just a small UITableView
in the middle of a UIViewController
. And I have a UIScrollView
filling the view controller embedding that table view.
I’ve registered for the keyboard notifications, UIKeyboardDidShowNotification
and UIKeyboardWillHideNotification
.
And in the method that fires when the keyboard appears, I've implemented a variation of this answer which does pretty much the same thing, setting the bottom
value of the UIEdgeInsets
which is used to set the contentInset
of the scroll view.
func keyboardWasShown(notification: NSNotification) {
var info: NSDictionary = notification.userInfo as NSDictionary
var keyboardSize: CGSize = info.objectForKey(UIKeyboardFrameBeginUserInfoKey).CGRectValue().size
let contentInsets: UIEdgeInsets = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0)
self.scrollView.contentInset = contentInsets
self.scrollView.scrollIndicatorInsets = contentInsets
}
The problem is it doesn't do anything. I successfully get the height of the keyboard but nothing changes. Can anybody tell me why and what I should do to fix this please?
Thank you.