iOS 8 presentationController determine if really is popover

后端 未结 8 935
暖寄归人
暖寄归人 2020-12-15 20:33

I\'m using the new adaptive \"Present As Popover\" capability of iOS 8. I wired up a simple segue in the StoryBoard to do the presentation. It works great on an iPhone 6 P

相关标签:
8条回答
  • 2020-12-15 21:27

    Solution that works with multitasking

    Assign the presenting controller as the popover's delegate

    ...
    controller.popoverPresentationController.delegate = controller;
    [self presentViewController:controller animated:YES completion:nil];
    

    Then, in the controller, implement the delegate methods:

    - (void)presentationController:(UIPresentationController *)presentationController willPresentWithAdaptiveStyle:(UIModalPresentationStyle)style transitionCoordinator:(id<UIViewControllerTransitionCoordinator>)transitionCoordinator
    {
        if (style != UIModalPresentationNone)
        {
            // Exited popover mode
            self.navigationItem.leftBarButtonItem = button;
        }
    }
    
    - (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
    {
        // Entered popover mode
        self.navigationItem.leftBarButtonItem = nil;
    }
    
    0 讨论(0)
  • 2020-12-15 21:32

    I check to see if the popoverPresentationController's arrowDirection is set after the view is laid out. For my purposes, this works well enough and covers the case of popovers on smaller screened devices.

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
    
        if (popoverPresentationController?.arrowDirection != UIPopoverArrowDirection.Unknown) {
            // This view controller is running in a popover
            NSLog("I'm running in a Popover")
        }
    }
    
    0 讨论(0)
提交回复
热议问题