UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTapTap:)];
[self.view1 addGestureRecognizer:tapGesture];
[self.view2 addGestureRecognizer:tapGesture];
[tapGesture release];
In the above code only taps on view2
are recognized. If I comment out the third line then taps on view1
are recognized. If I'm right and you can only use a gesture recognizer once, I'm not sure if this is a bug or it just needs some more documentation.
No you should not attach gesture recognizers to more than one view.
There is this explicit information in the Apple documentation:
Event Handling Guide for iOS - Gesture Recognizers Apple Developer Library
While as others mention they might work in some cases it is clearly against the documentation and could change in any future iOS version.
What you can do is add separate gesture recognisers to the views you want to monitor and they can share a common action.
What about re write (recreate) your GestureRecognize every time that you add a gesture recognizer pointing to the same func. In below case it works. I am using IBOutletCollection
Swift 2:
Override class by '
<UIScrollViewDelegate>
'And use this method in .m class:
This method will help you to enable multiple swipe on a single view..
You can do it using this code my views which are imageviews in the xib.