ScrollRangeToVisible: how to scroll to the start of a UITextView

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 {

//[textView scrollRectToVisible:CGRectMake(0, 0, 0, 0) animated:YES];

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.scrollEnabled = NO;
[textView resignFirstResponder];

NSRange range = NSMakeRange(0,1);
[textView scrollRangeToVisible:range];

}

+3
source share
2 answers

-1! :

NSRange range = NSMakeRange(0, 1);

0 ( ) 1 .

+5

, textView , , , . : :

- (void)killScroll :(UIScrollView*)scrollView 
{
    CGPoint offset = scrollView.contentOffset;
    offset.x -= 1.0;
    offset.y -= 1.0;
    [scrollView setContentOffset:offset animated:NO];
    offset.x += 1.0;
    offset.y += 1.0;
    [scrollView setContentOffset:offset animated:NO];
}

:

[yourTextView scrollsToTop];
-1

All Articles