I have been trying to solve this issue for a few days. I will appreciate any help. If it makes a difference to you, my app is free and used by a lot of people who have lost the ability to speak on their own.
The app is text to speech. I am implementing a feature where if they type text and then hit the Return key, the following will occur:
- the text will automatically be spoken
- the text will be saved to a temp location in case they have to repeat what they said
- the screen will be cleared and an Undo button appears, so they can add the text back to the textView if needed (for repeating).
The problem I am having is when the Return key is pressed, the cursor moves down a line. I think it looks weird to have a clear textView with the cursor a line down (picture below). The rest works, even the Undo feature. I have tried many suggestions I have found here for moving the cursor programmatically and nothing seems to work.
Here is the code I use to do the previous steps. Any suggestions appreciated.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
[self speakText];
self.clearedText = self.textView.text;
self.undoReady = YES;
[self.clearButton setTitle:@"Undo" forState:UIControlStateNormal];
self.textView.text = @"";
[WANT TO MOVE CURSOR TO BEGINNING POSITION];
}
}