How to use UIGestureRecognizerDelegate?

My setting

I am trying to copy the Google Now map interface.

I have a UIView that is a subspecies (inside) of a UIScrollView . Both are managed from the same UIViewController . UIView has a UIPanGestureRecognizer attached to it by a UIViewController .

UIScrollView used to scroll up and down. UIPanGestureRecognizer used to scroll UIView .

Problem

I can not scroll when I touch UIView (map)

Question

How to implement UIGestureRecognizerDelegate to enable gestureRecognizer(_:shouldRecognizeSimultaneouslyWithGestureRecognizer:) on the map so that it scrolls the UIScrollView ?

I spent several hours trying to figure it out, and I would be incredibly grateful for the help.

+5
source share
1 answer

In case someone wonders how to do this, here is the answer:

When you declare your class, add UIGestureRecognizerDelegate after the class that it subclasses. Here is how it looks in my case:

class CardViewController: UIViewController, UIGestureRecognizerDelegate

Then you add this function to the body of the UIViewController :

 func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } 

And finally, you do this with the UIPanGestureRecognizer :

somePanGestureRecognizer.delegate = self

+5
source

All Articles