1
votes

When I tap on a UIButton, a UIView MyView appear from the bottom a cover a third of the screen. I would like that when I tap somewhere outside this view, it disappears.

I thought about adding another transparent UIView right under MyView and add a tab gesture on it with the dismiss function but I'm sure there is something cleaner than this.

So I thought about adding the tap gesture MyTapGesture to dismiss MyView on self.view of the UIViewController. The problem is that outside this view, I have other UIControls and gestures that capture also any touch at the same time than MyTapGesture.

How can I make MyTapGesture the priority gesture outside MyView and ignore all other gesture, taps, etc...?

1
you are having two tap gesture menas? - Mukesh
menas? Yes I have a tap gesture on a subview of self.view. In that case, both are triggered. But when I tap on a UIButton, then only the tap of the UIButton is triggered. - Nico
Is this issue solved? - Omkar Guhilot
No really. I still had a problem while tapping on UIButtons. I fixed it by adding a transparent view right under my view but if you have a proper way, let me know. - Nico

1 Answers

1
votes

You may have to use the gesture delegate methods to handle two tapGestureRecognizer activate the one you need depending on scenario

#pragma mark - UIGestureRecognizerDelegate methods
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {

return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
   if ([tapGestureRecognizer1 isEqual:gestureRecognizer]) {

   return [tapGestureRecognizer2 isEqual:otherGestureRecognizer];
   }

 if ([tapGestureRecognizer2 isEqual:gestureRecognizer]) {

return [tapGestureRecognizer1 isEqual:otherGestureRecognizer];
}

return NO;
}