iOS开发-如何获取UITextView光标的位置

- (void)textViewDidBeginEditing:(UITextView*)textView {

      [self performSelector:@selector(textViewDidChange:) withObject:textView afterDelay:0.1f];

}

- (void)textViewDidChange:(UITextView*)textView {

      CGFloat cursorPosition;

      if (textView.selectedTextRange) {

          cursorPosition = [textView caretRectForPosition:textView.selectedTextRange.start].origin.y;

      } else {

          cursorPosition =0;
      }

}

推荐阅读更多精彩内容