//You can got the selection range of the textView, and you can get the "stringToCursor" from head to the cursor.
int Len = inputTextView.selectedRange.location;
NSString *allString = inputTextView.text;
NSString *stringToCursor = [allString substringToIndex:Len];
// Separate the "stringToCursor" by "/n"
NSArray *strarr = [cursorString componentsSeparatedByString:@"/n"];
int row = [strarr count];
for (int i = 0; i < [strarr count]; i++) {
NSString *rowString = [strarr objectAtIndex:i];
row += [self getRowNum:rowString];
}
// caculate the x ordinate
float xOrdinate = [[strarr lastObject] sizeWithFont:[inputTextView font]].width;
// caculate the y ordinate
CGSize size = [[inputTextView text] sizeWithFont:[inputTextView font]];
float hei = size.height;
float tvOffset = inputTextView.contentOffset.y;
float yOrdinate = row * hei - tvOffset;