简体   繁体   English

iOS UITableView仅对第一个可见单元进行动画处理

[英]iOS UITableView animating only first visible cell

I want to implement an UITableView with some animation while the user is scrolling. 我想在用户滚动时用一些动画实现UITableView Only the first visible (top most) cell has to be an different layout. 只有第一个可见(最顶部)单元格必须具有不同的布局。 Before the second cell reaches the top of UITableView I want to start the small animation. 在第二个单元格到达UITableView的顶部之前,我想开始小动画。 (changing background alpha and width of cells contentView etc.) (更改背景Alpha和单元格contentView的宽度等)

How could I handle this? 我该如何处理?

[UPDATE] [UPDATE]

What I have tried so far: 到目前为止我尝试过的是:

  • using UIScrollView delegate method scrollViewDidScroll:(UIScrollView *)scrollView together with UITableView´s visibleCells property using the first item of it to get the reference with no luck 使用UIScrollView委托方法scrollViewDidScroll:(UIScrollView *)scrollView和UITableView的visibleCells属性,并使用它的第一项来获得引用,但没有运气

This is what I have done: 这是我所做的:

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

}

The problem appears, if the user is scrolling down because the animated cell is still visible and the next one gets animated. 如果用户由于动画单元格仍然可见而下一个动画化,而用户向下滚动,则会出现问题。 So two or more cells are animated. 因此,对两个或更多单元进行动画处理。 I could going on and implement an method in my custom cell like - (void) resetAnimatedCell but maybe there is an much more elegant way for doing this? 我可以继续在我的自定义单元中实现一个方法,例如- (void) resetAnimatedCell但是也许有一种更优雅的方法来做到这一点?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM