-2

I have UIScrollView and I added UIView over it and I added gesture recognizers to UIView. I added tap gesture and swipe gestures to UIView and it works fine. But when user use pinch then I want to be ignore by UIView and UIScrollView should react to this gesture. How can I do it? I can't anyway how to do this. I know there is hit test method but I don't think it could help me.

Edit: I have UIView at the top which now captures (catch) all gestures. For tap and swipe gestures it's what I want. But I want to pinch gesture would be ignore by top UIViewand get catched by UIScrollView below that UIView. I've tried to search for solution but I can't found any.

Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182
  • The broken English in your question makes your setup and goal unclear. Please refine your question. – Holly Dec 07 '16 at 15:34
  • I've edited it and hope now it's more clear what I want. – Libor Zapletal Dec 07 '16 at 15:39
  • 1. Without the gestures added to sub view, does your scroll view get the 'pinch' gesture (like if you are trying to use pinch to zoom .. does it work if you set `userInteractionEnabled=false` for the UIView) – Swapnil Luktuke Dec 08 '16 at 18:56
  • 2. Add **some** code to your question if you want good answers. Please do not add your entire class. Only the code where you create, add, and handle the gestures (and gesture delegate if relevant) – Swapnil Luktuke Dec 08 '16 at 18:58
  • Why are you adding an UIView on top of UIScrollView? If it's only to prevent UIScrollView from getting those gestures, then it's a wrong approach. Describe what do you want to achieve by doing this. – Łukasz Przytuła Dec 12 '16 at 10:33

2 Answers2

0

Have you tried disabling the user interaction at any instance by following code:

scrollViewObject.userInteractionEnabled = NO;

Should help.

ios_Dev
  • 95
  • 1
  • 10
0

If your UIView is on top and is capturing all gestures, setup the delegate method gestureRecognizerShouldBegin and get it to detect the type of gesture. If its a pinch then call a method on your UIScrollView

func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
    if gestureRecognizer.isKind(of: UIPinchGestureRecognizer.self) {
        scrollView.someFunction()
    }
    return true
}

You can also pass an instance of the pinch gesture to your scrollview function if you wish.

Hodson
  • 3,438
  • 1
  • 23
  • 51