Pergunta

I have created a cover flow layout by subclassing UICollectionViewFlowLayout.

There is an animation that pushes one item to center of the screen based on the method:

-(CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity

I need to find a way of knowing which item is this in order to make something with the related data item.

How can I achieve this? Can't seem to find a way.

Foi útil?

Solução

There is no method on UICollectionView to give you this so here's what I do (iPad, fixed Portrait mode with a collection view subview smaller than the screen, so you probably want to be a bit more clever with the CGPoint);

// Get path for cell in centre
UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
CGPoint pointInScreenCoords = CGPointMake(384, 512);
CGPoint pointInWindowCoords = [mainWindow convertPoint:pointInScreenCoords fromWindow:nil];
CGPoint pointInViewCoords = [self.collectionView convertPoint:pointInWindowCoords fromView:mainWindow];

NSIndexPath* centreIndexPath = [self.collectionView indexPathForItemAtPoint:pointInViewCoords];

Depending on how often you require this to update you can put it in the scroll view delegate's didScroll method, didEndScrolling or just call when required.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top