2014-05-20 68 views
1

我想在用戶滾動時用一些動畫實現UITableView。只有第一個可見的(最上面的)單元必須是不同的佈局。在第二個細胞到達UITableView的頂部之前,我想開始小動畫。 (改變單元格的背景alpha和寬度contentView等)iOS UITableView只動畫第一個可見單元格

我該如何處理?

[更新]

我迄今爲止嘗試:用

  • UIScrollView的委託方法scrollViewDidScroll:(UIScrollView *)scrollView 連同UITableView's visibleCells財產使用它的第一個項目,以獲得 參考無運氣
+0

到目前爲止你有嘗試過嗎? – Pancho

回答

1

這就是我所做的:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { 

    if (!decelerate) { 
      [self scrollingFinish]; 
    } 
} 

..

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 
    [self scrollingFinish]; 
} 

..

- (void)scrollingFinish { 

    NSIndexPath *firstVisibleIndexPath = [[self.tableView indexPathsForVisibleRows] objectAtIndex:0]; 

    NSLog(@"first visible cell's section: %i, row: %i", (int) firstVisibleIndexPath.section, (int) firstVisibleIndexPath.row); 


    APFCategoryCell * cell = (APFCategoryCell*) [self.tableView cellForRowAtIndexPath:firstVisibleIndexPath]; 

    [cell animateCell]; 

    [self.tableView scrollToRowAtIndexPath:firstVisibleIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; 

} 

出現的問題,如果用戶上下滾動,因爲動畫細胞仍然可見,下一個被動畫。所以兩個或更多的單元格是動畫的。我可以繼續在我的自定義單元格中實現一個方法,例如- (void) resetAnimatedCell,但也許有更好的方法來做到這一點?

相關問題