0

I want to dismiss a modal view in iOS (non full screen modal on iPad) when user taps outside the modal view.

A possible way suggested on some of the SO answers was to add a UITapGestureRecognizer to window (Iphone SDK dismissing Modal ViewControllers on ipad by clicking outside of it). However, this adds the tap recognition in my case, but taps are only being detected when they are made inside the bounds of the modal, and not when outside modal.

Since the taps outside the modal bounds are not being detected at all, how do I dismiss the modal?

Community
  • 1
  • 1
basum
  • 319
  • 1
  • 3
  • 18

1 Answers1

0

Try this code . The if condition checks if the touch is not in the view.

   - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
    {
        UITouch *touch = [[event allTouches] anyObject];
        for (UIView* subView in self.subviews) 
        {
            if(![subView pointInside:[self convertPoint:touch toView:subView] withEvent:event])
            {
               NSLog(@"Dismiss modal view here");
            }
        }
    }
DHEERAJ
  • 1,478
  • 12
  • 32