I know this is an old question, but it is possible despite saying the โrightโ answer. Since this was the first result when I looked for it, I decided to clarify:
Here's how you do it:
You need to add the property to the view controller from which you want to present modally, in my case "tapBehindGesture".
then in viewDidAppear
if(!tapBehindGesture) { tapBehindGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBehindDetected:)]; [tapBehindGesture setNumberOfTapsRequired:1]; [tapBehindGesture setCancelsTouchesInView:NO];
And here is the implementation for tapBehindDetected
- (void)tapBehindDetected:(UITapGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateEnded) { //(edited) not working for ios8 above //CGPoint location = [sender locationInView:nil]; //Passing nil gives us coordinates in the window CGPoint location = [sender locationInView: self.presentingViewController.view]; //Convert tap location into the local view coordinate system. If outside, dismiss the view. if (![self.presentedViewController.view pointInside:[self.presentedViewController.view convertPoint:location fromView:self.view.window] withEvent:nil]) { if(self.presentedViewController) { [self dismissViewControllerAnimated:YES completion:nil]; } } } }
Remember to remove tapBehindGesture from view.window in viewWillDisappear to avoid running handleTapBehind in an unallocated object.
Ares Apr 04 '13 at 18:45 2013-04-04 18:45
source share