2013-02-15 55 views
3

我試圖讓我的UITableView以穩定的速度緩慢向下滾動,我可以指定。我已經使用scrollToRowAtIndexPath,但是不管我是否選擇對其進行動畫製作,這幾乎是一次即時動作。我正在看一些動作要慢得多的東西。讓UITableView在設定的時間內從上到下滾動?

我確實想知道我是否可以用UIView動畫塊做某件事,一次移動一個indexPath.row,但由於我的細胞高度不同,這會導致動畫速度不均勻。

我能做到這一點的其他方式嗎?

回答

3

我這個懂了..

[NSTimer scheduledTimerWithTimeInterval: 0.025 target:self selector:@selector(scrollTableView) userInfo:nil repeats:YES]; 

和..

- (void) scrollTableView { 

    float w = 1; 

    CGPoint scrollPoint = self.tableView.contentOffset; 
    scrollPoint.y = scrollPoint.y + w; 
    if (scrollPoint.y >= self.tableView.contentSize.height - (self.tableView.frame.size.height - 100) || scrollPoint.x <= -self.tableView.frame.size.height + 924) { 
    w *= -1; 
    } 
    [self.tableView setContentOffset: scrollPoint animated: NO]; 
} 
+1

確保你處理用戶與表交互,而你做到這一點,以及在用戶離開視圖控制器。 – rmaddy 2013-02-15 23:46:27

0

隨着時間的推移,您始終可以遞減contentOffset y軸。

+0

這正是我剛剛做了:) – Luke 2013-02-15 22:24:31

0

在這裏你去好友。只需將animateWithDuration更改爲更高的秒數(如1或1.5),以查看它是否達到了所需的效果。確保在* .m文件中包含QuartzCore庫和#import <QuartzCore/QuartzCore.h>。這是那麼容易,因爲它得到

-(IBAction)modeTableSlowly 
{ 

    [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ 

      //here tblSimpleTable2 is tableView 
      [tblSimpleTable2 setFrame:CGRectMake(183, 56, 137, 368)]; 

    } completion:nil]; 

}