Getting the screen location of a cell from a UICollectionView

前端 未结 6 1439
野性不改
野性不改 2021-01-30 10:20

This isn\'t so much a question as an explanation of how to solve this problem.

The first thing to realize is that the UICollectionView does inherit from a <

6条回答
  •  心在旅途
    2021-01-30 11:09

    -(void)collectionView:(UICollectionView *)cv didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
    {
    
    UICollectionViewLayoutAttributes *attributes = [cv layoutAttributesForItemAtIndexPath:indexPath];
    
    CGRect cellRect = attributes.frame;
    
    CGRect cellFrameInSuperview = [cv convertRect:cellRect toView:[cv superview]];
    
    NSLog(@"%f",cellFrameInSuperview.origin.x);
    }
    

    It work for me.You can try yourself

提交回复
热议问题