How to enlarge hit area of UIGestureRecognizer?
cocoa-touch, ios, ipad, iphone, uikit
Solution
If you are doing this for a custom `UIView`, you should be able to override the `hitTest:withEvent:` method:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
CGRect frame = CGRectInset(self.bounds, -20, -20);
return CGRectContainsPoint(frame, point) ? self : nil;
}
The above code will add a 20 point border around the view. Tapping anywhere in that area (or on the view itself) will indicate a hit.
Problem
I'm using few gesture recognizers on some views, but sometimes views are too small and it's hard to hit it. Using recognizers is necessary, so how can I enlarge hit area?