Dismiss modal view form sheet controller on outside tap

前端 未结 13 1068
猫巷女王i
猫巷女王i 2020-12-01 06:16

I am presenting a modal view controller as a form sheet and dismissing it when the cancel button, which is a bar button item, is clicked. I need to dismiss it when I tap on

13条回答
  •  不知归路
    2020-12-01 06:59

    Here is my version that works for iOS 7 and iOS 8 and does not require conditional swapping of coordinates:

    - (void)handleTapBehind:(UITapGestureRecognizer *)sender
    {
        if (sender.state == UIGestureRecognizerStateEnded)
        {
            CGPoint location = [sender locationInView:self.view];
    
            if (![self.view pointInside:location withEvent:nil]) {
                [self.view.window removeGestureRecognizer:self.recognizer];
                [self dismissViewControllerAnimated:YES completion:nil];
            }
        }
    }
    

提交回复
热议问题