iOS 8 presentationController determine if really is popover

后端 未结 8 946
暖寄归人
暖寄归人 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)transitionCoordinator
    {
        if (style != UIModalPresentationNone)
        {
            // Exited popover mode
            self.navigationItem.leftBarButtonItem = button;
        }
    }
    
    - (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
    {
        // Entered popover mode
        self.navigationItem.leftBarButtonItem = nil;
    }
    

提交回复
热议问题