I need to implement a feature that will invoke some code when I double tap on the self.view (view of UIViewCotroller
). But the problem that I have other UI object on this view and I don't want to attach any recognizer object to all of them. I found this method below how to make gesture on my view and I know how it works. Right now I am in front of handicap which way to choose for create this recognizer ignoring subview. Any ideas? Thanks.
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[self.view addGestureRecognizer:doubleTap];
Best Answer
You should adopt the
UIGestureRecognizerDelegate
protocol inside theself
object and call the below method for checking the view. Inside this method, check your view againsttouch.view
and return the appropriate bool (Yes/No). Something like this:Edit: Please, also check @Ian's answer!
Swift 5