I am presenting a popover controller(with ViewController.modalPresentationStyle = UIModalPresentationPopover;
) from left bar button action. And in right bar button action I am triggering a push segue. Ideally, when popover is visible the interaction to views behind popover should not happen. But, even if the popover is visible, I can click on the right bar button and its pushing new view controller without dismissing the popover.
My code is
- (UIViewController *)menuViewController {
if (!_menuViewController) {
_menuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"TableViewController"];
_menuViewController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popoverPresentationController = _menuViewController.popoverPresentationController;
popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
}
return _menuViewController;
}
- (IBAction)leftAction:(id)sender {
self.menuViewController.popoverPresentationController.barButtonItem = sender;
[self presentViewController:self.menuViewController animated:YES completion:nil];
}
- (IBAction)rightAction:(id)sender {
[self performSegueWithIdentifier:@"PushSegue" sender:nil];
NSLog(@"Crap here");
}
I tried setting popover presentation controller's passthroughViews
to nill and empty array, but no result
How to disable all interaction when popover is visible?
UPDATE :
This is happening if the popover is visible and we have any interaction in navigation bar. In short, its taking interaction for navigation bar even if the popover is visible. Is there any way to disable this?
Set the passthroughViews
to nil on another run loop after presenting the popover. You can do like this.
self.presentViewController(_menuViewController, animated: true) { () -> Void in
dispatch_async(dispatch_get_main_queue()) { () -> Void in
popoverPresentationController.passthroughViews = nil;
}
}
For further explanation, check this http://karmeye.com/2014/11/20/ios8-popovers-and-passthroughviews/