You can think of a UITapGestureRecognizer placed on top of everything that triggers a reject only when a touch occurs outside your UIControl borders.
Sort of
- (void)presentConfirm { // whatever self.dismissRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss:)]; self.dismissRecognizer = self; [self.view addGestureRecognizer:self.dismissRecognizer]; } - (void)dismiss:(UIGestureRecognizer *)gestureRecognizer { // do stuff [self.view removeGestureRecognizer:self.dismissRecognizer]; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { CGPoint touchPoint = [touch locationInView:self.view]; return !CGRectContainsPoint(self.control.frame, touch)); }
Basically, you only run the dismiss method when the touch happens outside of the UIControl framework (I assumed that your control is listed as self.control ).
You will also need the dismissRecognizer property declared as
@property (nonatomic, strong) UITapGestureRecognizer *dismissRecognizer;
and to prevent warnings, you should also declare that your controller complies with the UIGestureRecognizerDelegate protocol.
source share