UITextView contentInset导致跳转口吃

时间:2014-12-24 16:30:23

标签: ios objective-c xcode swift uitextview

我已将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
}

enter image description here

enter image description here

我也注意到只有当内容很短时才会发生。当它被一篇长篇文章填满时,就不会因为口吃而跳跃。

我在iOS 8上运行它。有什么帮助吗?

更新

它似乎与文本长度无关,而是空行。当文本中有空行时,就会发生跳跃口吃。

0 个答案:

没有答案