In my app, when I click on a text field, the keyboard hides it. Please help me -- how can I move my view up when I click on the text field. I'm using this code in textFieldDidBeginEditing:
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 216, 0);
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 216, 0);
but it doesn't work.
You should not trust textFieldDidBeginEditing:
to adjust for the keyboard, since this method will be called even if the user is typing using a physical keyboard where an onscreen keyboard will not be displayed.
Instead listen to the UIKeyboardWillShowNotification
, that is only triggered when the keyboard will actually be displayed. You need to do a three step process:
userInfo
dictionary. The size will differ from landscape/portrait, and different devices.contentInset
using the determined size. You can do it animated, the notification will even tell you the duration for the keyboard animation.You find more information and sample code from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With