2

Based on the page change of a paged UIScrollView, I'm calling scrollToRowAtIndexPath:atScrollPosition:animated to the table specifics for that page that's in display.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat pageWidth = self.scrollView.frame.size.width;
    int page = floor((self.scrollView.contentOffset.x - pageWidth/2)/pageWidth)+1;
    self.pageControl.currentPage = page;
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:page];
    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

However, the animation of the automatic scrolling is happening too slow. Is there a way to make this animation more snappy?

Oscar Swanros
  • 19,767
  • 5
  • 32
  • 48

1 Answers1

19

A fast solution might be:

[UIView animateWithDuration:aSmallValue animations:^{
        [self.tableView scrollToRowAtIndexPath:indexPath
                              atScrollPosition:UITableViewScrollPositionTop 
                                      animated:NO];
}];
danypata
  • 9,895
  • 1
  • 31
  • 44
  • @danypata I want to know the difference between your method and Oscar Swanros's method? – BlackMamba Jan 17 '14 at 05:37
  • The problem was that the scroll is to slow for the `scrollToRowAtIndexPath", "scrollToRowAtIndexPath" speed is computed depending on the content size, but if you want the same speed for any content size, then you can use my method. – danypata Jan 17 '14 at 10:05
  • 1
    Even with no animation it's slow for me – Rodrigo Ruiz May 29 '16 at 08:26