AlanQuatermain / AQGridView

A grid view for iPhone/iPad, designed to look similar to NSCollectionView.
http://quatermain.tumblr.com/
BSD 3-Clause "New" or "Revised" License
2.37k stars 450 forks source link

Hit test not working for cells in a second column + possible fix #209

Open VirtualDiveGuide opened 10 years ago

VirtualDiveGuide commented 10 years ago

I couldn't get the following AQGridView function to return YES for cells in the second column of the grid when tapped:

I got it working by replacing:

 CGPoint hitCenter = [self convertPoint:[hitView center] fromView:hitView];

for ( AQGridViewCell *aCell in [[self visibleCells] copy])
{

    if ( CGRectContainsPoint( aCell.frame, hitCenter ) )
    return ( YES );

}

with:

UIView *parent = hitView.superview;
while (parent != nil)
{
    if ([parent isKindOfClass:[AQGridViewCell class]])
    {
        return ( YES );
    }
    parent = parent.superview;
}

This could possibly even be a bug with UIView's:

(hitCenter was outside the grid view but debugging the views in the hierarchy suggests this could not be the case.)