2013-06-12 171 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