我已将keyboardDismissMode
设为.Interactive
,我想在键盘出现时更改UITextView的contentInset,就像iOS 7和8中的消息应用程序一样。但是,它会导致跳转卡顿当键盘消失时。
这是我的代码。
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
}
我也注意到只有当内容很短时才会发生。当它被一篇长篇文章填满时,就不会因为口吃而跳跃。
我在iOS 8上运行它。有什么帮助吗?
更新
它似乎与文本长度无关,而是空行。当文本中有空行时,就会发生跳跃口吃。