Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find a UICollectionViewCell's coordinates relative to the App Window

Is it possible to translate a UICollectionViewCell's coordinates from being relative to the UICollectionView to being relative to the superview? So far I've been unable to translate a UICollectionViewCell's coordinates when touched to the superview. Here's what I've tried so far:

- (void)collectionView:(UICollectionView *)collectionView  
        didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = 
     [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" 
                                               forIndexPath:indexPath];

    CGRect frame = CGRectMake(0.0, 
                              0.0,  
                              cell.frame.size.width, 
                              cell.frame.size.height);
    frame.origin = [cell convertPoint:cell.frame.origin 
                               toView:self.view];
}

I'd like to create a new frame which originates from the cell's position on the view, not in the UICollectionView. Any help would be great thanks.

like image 692
Dan Lister Avatar asked Nov 25 '12 18:11

Dan Lister


1 Answers

Just in case if anybody looking for this, here is how it can be done in Swift:

let cellFrameInSuperview = collectionView.convertRect(collectionView.cellForItemAtIndexPath(indexPath)!.frame, toView: view)
like image 187
AydinAngouti Avatar answered Sep 22 '22 16:09

AydinAngouti