Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll UITextView to bottom without animation

I have the following code which scrolls a textview to the bottom with animation.

- (void)scrollTextViewToBottom:(UITextView *)textView {
    [_logTextView scrollRangeToVisible:NSMakeRange([_logTextView.text length], 0)];
}

I've seen some other examples that use contentOffset but that may have a bug? as it gives inconsistent results.

like image 786
kreek Avatar asked Mar 13 '15 00:03

kreek


Video Answer


2 Answers

Perhaps you can try:

- (void)scrollTextViewToBottom:(UITextView *)textView {

    [UIView setAnimationsEnabled:NO];
    [_logTextView scrollRangeToVisible:NSMakeRange([_logTextView.text length], 0)];
    [UIView setAnimationsEnabled:YES];

}
like image 193
Michael Avatar answered Oct 06 '22 01:10

Michael


CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
[self.scrollView setContentOffset:bottomOffset animated:NO];
like image 30
MaappeaL Avatar answered Oct 06 '22 01:10

MaappeaL