I'm writing a module that everytime I swipe on a view, two sub views with a half size of the view will be added. Those subviews have their own gestures (eg: pan,...). The first time I swipe, it's OK because none of subview has been created. But once the subview been created, everytime I swipe, the swipe gesture is alway pass to its subviews. :(, so I have to swipe 2 times to divide.
I want to know is there any way to block swipe passing to its subview? Thank you.
UPDATE
I used shouldRecognizeSimultaneouslyWithGestureRecognizer to make those gestures work simultaneously. But there's still have some problems. The parent view have its Swipe gesture, the subview have its Pan gesture. Since I use souldRecognizeSimultaneouslyWithGestureRecognizer, sometime when I'm panning, the swipe gesture triggers. So, you know how to disable Swipe while Pan is active in this situation?
To block all gesture recognizers from superviews I created a UIGestureRecognizer sub class that will do just that when attached to a view. See the following code (taken from my WEPopover project):
If you want to block all gesture recognizers attached to parent views of some view, just do the following:
You have to implement the UIGestureRecognizerDelegate method:
And add your controller as the delegate of the gesture recognizers. Then, when two gesture recognizers respond to a gesture, this method will be called and here you can implement the logic you want for your app.
In the interface declaration of the controller you have to type:
Then, when creating the gesture recognizer:
And then, finally, you add this method to the controller:
EDIT You can also implement
And here, detect if you have already presented the subviews, and block any gesture you want.
Considering that I have a
dialogView
as a direct subview of myUIViewController
's mainview
I'm attaching a gesture recognizer to the mainview
and do the following (setting my view controller as the gesture recognizerdelegate)
:set userinteractionEnabled to NO of your subView
if you dont want to disable userInteraction then use
cancelsTouchesInView
methodtry like this,