Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enlarge hit area of UIGestureRecognizer?

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?

like image 482
Tesseract Avatar asked Mar 21 '13 17:03

Tesseract


People also ask

What is Pan gesture in Swift?

A pan gesture occurs any time a person moves one or more fingers around the screen. A screen-edge pan gesture is a specialized pan gesture that originates from the edge of the screen. Use the UIPanGestureRecognizer class for pan gestures and the UIScreenEdgePanGestureRecognizer class for screen-edge pan gestures.

What is UIGestureRecognizer?

A gesture recognizer decouples the logic for recognizing a sequence of touches (or other input) and acting on that recognition.


1 Answers

Swift version of @rmaddy answer:

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    let frame = self.bounds.insetBy(dx: -20, dy: -20);
    return frame.contains(point) ? self : nil;
}
like image 57
Marcin Mierzejewski Avatar answered Sep 19 '22 15:09

Marcin Mierzejewski