简体   繁体   中英

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.

Perhaps you can try:

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

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

}
CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
[self.scrollView setContentOffset:bottomOffset animated:NO];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM