Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is what I come up with. The key is to override <code>scrollViewShouldScrollToTop:</code> method. And to return NO to prevent the default behavior.<br> One thing to be aware of is that <code>scrollViewShouldScrollToTop:</code> won't be called if the content of the scroll view is already at the top of the scroll view. See the trick in the code below. </p> <pre><code>@interface ViewController () &lt;UIScrollViewDelegate&gt; @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 2); // if the scrollView contentOffset is at the top // (0, 0) it won't call scrollViewShouldScrollToTop self.scrollView.contentOffset = CGPointMake(0, 1); } - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView { // call your custom method and return YES [self scrollToBottom:scrollView]; return NO; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { // be sure that when you are at the top // the contentOffset.y = 1 if (scrollView.contentOffset.y == 0) { scrollView.contentOffset = CGPointMake(0, 1); } } - (void)scrollToBottom:(UIScrollView *)scrollView { // do whatever you want in your custom method. // here it scrolls to the bottom CGRect visibleRect = CGRectMake(0, scrollView.contentSize.height - 5, 1, 1); [scrollView scrollRectToVisible:visibleRect animated:YES]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload