We currently are using a solution similar to the one mentioned here (see Ares's answer). This does not seem to work in iOS8.
I have a form sheet, and I want to dismiss it as soon as the user taps on the dimmed view 'behind' the form sheet. Previously, this seemed possible by adding a gesture recogniser to the window, and checking tap-location to see if it was outside the current form sheet;
I also noticed the point needs to be converted (switch x and y) of the device is used in landscape mode. Other than that, right now it only receives gestures that occurred from inside the form sheet, where before any tap gesture anywhere on the screen would trigger an event.
- (void)viewDidLoad
{
[super viewDidLoad];
self.recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehind:)];
self.recognizer.numberOfTapsRequired = 1;
self.recognizer.cancelsTouchesInView = NO;
[self.view.window addGestureRecognizer:self.recognizer];
}
- (void)handleTapBehind:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded)
{
CGPoint location = [sender locationInView:nil];
if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) && IOS8)
{
location = CGPointMake(location.y, location.x);
}
// if tap outside pincode inputscreen
BOOL inView = [self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil];
if (!inView)
{
[self.view.window removeGestureRecognizer:sender];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
}
As mentioned in the thread you referenced, you should add a UIGestureRecognizerDelegate
and implement the methods:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return YES;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With