I have enabled the keyboardDismissMode
to be .Interactive
, and I want to change the contentInset of UITextView when keyboard appears, just like the Message App in iOS 7 and 8. However, it causes jump stutters when keyboard disappears.
Here is my code.
func keyboardWillShow(notification: NSNotification) {
var info: NSDictionary = notification.userInfo!
var keyboardSize: CGSize = info.objectForKey(UIKeyboardFrameEndUserInfoKey)!.CGRectValue().size
self.textView.contentInset = UIEdgeInsetsMake(64, 0, keyboardSize.height, 0)
self.textView.scrollIndicatorInsets = self.textView.contentInset
// 64 is the UINavigationBar height and 44 is the UIToolBar below. The Toolbar is the inputAccessory
}
func keyboardWillHide(notification: NSNotification) {
// Change contentInset
self.textView.contentInset = UIEdgeInsetsMake(64, 0, 44, 0)
self.textView.scrollIndicatorInsets = self.textView.contentInset
}
I have also noticed that it only happens when the content is short. When it is filled with a long essay, it wouldn't jump with stutter.
I am running this on iOS 8. Any help?
Update:
It appears that its not related to the text length, but an empty line. The jump stutter happen when there is an empty line in the text.