Initial headache: I'm trying to scroll to the very top of my UITextView as soon as the keyboard is fired. I tried to extract an answer from it, but I am afraid that this did not help.
I thought I was doing this with scrollRectToVisible, but nothing happens. Then I thought I should try scrollRangeToVisible, but this crashed my application ... I'm sure I did something extremely upset and wrong. I would be very happy if anyone could help:
- (IBAction)hideKeyboard:(id)sender {
NSRange range = NSMakeRange(textView.text.length - (textView.text.length+1),1);
[textView scrollRangeToVisible:range];
textView.scrollEnabled = NO;
[textView resignFirstResponder];}
EDIT:
updated code for those facing a similar problem:
- (IBAction)hideKeyboard:(id)sender {
[textView resignFirstResponder];
NSRange range = NSMakeRange(0,1);
[textView scrollRangeToVisible:range];
}
source
share