获取 UITextView 的光标位置

来源:互联网 发布:mac 显示器校准 编辑:程序博客网 时间:2024/05/01 04:06
- (void)textViewDidBeginEditing:(UITextView *)textView {    [self performSelector:@selector(textViewDidChange:) withObject:textView afterDelay:0.1f];}- (void)textViewDidChange:(UITextView *)textView {    [self.tableView beginUpdates];    [self.tableView endUpdates];        CGFloat cursorPosition;    if (textView.selectedTextRange) {        cursorPosition = [textView caretRectForPosition:textView.selectedTextRange.start].origin.y;    } else {        cursorPosition = 0;    }    CGRect cursorRowFrame = CGRectMake(0, cursorPosition, kScreenWidth, kMinTextViewHeight);    CGRect textViewFrame = [self.tableView convertRect:cursorRowFrame fromView:textView];        [self.tableView scrollRectToVisible:textViewFrame animated:YES];}
0 0
原创粉丝点击