2013-06-12 57 views
2

根据分页UIScrollView的页面更改,我打电话给scrollToRowAtIndexPath:atScrollPosition:animated查看显示的页面的表格细节。scrollToRowAtIndexPath:atScrollPosition:动画滚动速度太慢

- (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]; 
} 

但是,自动滚动的动画发生得太慢。有没有办法让这个动画更加活泼?

+0

你谈论的设备或模拟器上运行? –

+0

这两个动画都很慢。 –

+1

尝试使用不带动画的“scrollToRowAtIndexPath”,并将该行添加到可为其设置动画持续时间的“UIView”动画块中。 – danypata

回答

16

一个快速的解决方案可能是:

[UIView animateWithDuration:aSmallValue animations:^{ 
     [self.tableView scrollToRowAtIndexPath:indexPath 
           atScrollPosition:UITableViewScrollPositionTop 
             animated:NO]; 
}]; 
+0

它的工作,谢谢。 –

+0

@danypata我想知道你的方法和Oscar Swanros的方法之间的区别吗? – BlackMamba

+0

问题在于scrollToRowAtIndexPath的滚动速度较慢,scrollToRowAtIndexPath的速度取决于内容的大小,但是如果您希望内容大小的速度相同,那么您可以使用我的方法。 – danypata