I have a UICollectionView
where cells are text sized so the whole thing may end up being only about 13 or 30pt tall, depending. Needless to say, the cells are really hard to tap.
To solve this problem, I'm trying to send nearby tap events into the collection view with hitTest:withEvent:
and pointInside:withEvent:
.
CGPoint ShiftNearbyPointInside(CGPoint point, CGRect bounds, CGFloat radius) {
if (point.y < 0 && point.y > -radius) {
point.y = 1;
}
if (point.y > CGRectGetMaxY(bounds) && point.y < CGRectGetMaxY(bounds) + radius) {
point.y = CGRectGetMaxY(bounds) - 1;
}
return point;
}
@implementation MyCollectionView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
return [super hitTest:ShiftNearbyPointInside(point, self.bounds, self.enlargedTapRadius) withEvent:event];
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
return [super pointInside:ShiftNearbyPointInside(point, self.bounds, self.enlargedTapRadius) withEvent:event];
}
@end
This works for highlighting. If I touch within enlargedTapRadius
points from the top or bottom of the collection view, the cell becomes highlighted, but when I release, the delegate is never called. I'm using a similar technique for a UIButton
and it works well. Is there something else needed to get the touch up event to sink in?