This is the closest I came to a solution for this:
I implement the method UITextViewDelegate textView:shouldChangeTextInRange:replacementText:and check if the entered text is a line break not at the end of the text. In this case, I add a space to it and put it in the text view. This leads to the fact that the carriage appears in the center, as it should be.
The only drawback to this is that you have a space that the user did not enter, and if he deletes it, then the carriage moves to the left again. However, it is better than nothing.
This is the code I used:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
BOOL isMidTextLinebreak = [text isEqualToString:@"\n"] && range.location != textView.text.length;
if (isMidTextLinebreak) {
NSMutableString *updatedText = [[NSMutableString alloc] initWithString:textView.text];
text = [text stringByAppendingString:@" "];
[updatedText insertString:text atIndex:range.location];
textView.text = updatedText;
NSRange newRange = range;
newRange.location += text.length;
textView.selectedRange = newRange;
}
return !isMidTextLinebreak;
}