UITextView cursor below frame when changing frame

前端 未结 9 440
名媛妹妹
名媛妹妹 2020-12-01 06:50

I have a UIViewCOntrollerthat contains a UITextView. When the keyboard appears I resize it like this:

#pragma mark - Responding to          


        
9条回答
  •  执笔经年
    2020-12-01 07:36

    A lot of answers already, I found that in my case it's actually much simpler. On keyboardWillShow I adjust the text view's contentInset and keep the frame full screen. And while scrollRangeToVisible: is not working for me like for so many others, the scroll view methods (from which UITextView inherits) work just fine. This works for me:

    - (void)textViewDidChange:(UITextView *)textView
    {
        CGRect caret = [_textView caretRectForPosition:_textView.selectedTextRange.end];
        [_textView scrollRectToVisible:caret animated:YES];
    }
    

提交回复
热议问题