简体   繁体   中英

UICollectionViewCell: can I know exactly when the cell appears and disappears?

I need to do some animation in a UICollectionViewCell , and I want to start the animation when the cell appears and stop/pause it when it disappears.

I guess there's no single method that tells me exactly what I want? I'm looking at:

collectionView:cellForItemAtIndexPath: I guess this isn't the place when the cell appears and visible, because it gets called even in viewDidLoad of my view controller.

layoutSubviews and didMoveToSuperview The problem is that, UICollectionView could pre-loads a cell offscreen, in this case these two won't work.

Thanks!

try using

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell  forItemAtIndexPath:(NSIndexPath *)indexPath;

and

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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