2014-05-20 72 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,但也许有更好的方法来做到这一点?

相关问题