0

我想在 UIPopoverPresentationController 中呈现一个 viewController,就像我们选择语言时 iOS Setting App 所做的那样。它在设备屏幕的中心呈现了一个 viewController! 在此处输入图像描述

但是,我的结果不是这样的!

在此处输入图像描述

这是我的代码:

func rightButtonPressed(rightBarButton: UIBarButtonItem) {
    let detailVC = self.storyboard?.instantiateViewControllerWithIdentifier("ExampleViewController") as! ExampleViewController
    detailVC.modalPresentationStyle = .Popover
    let popOverVC = detailVC.popoverPresentationController
    popOverVC?.permittedArrowDirections = .Any
    popOverVC?.barButtonItem = rightBarButton
    popOverVC?.sourceView = self.view
    popOverVC?.delegate = self

    self.presentViewController(detailVC, animated: true, completion: nil)
}

和代表:

extension DetailViewController: UIPopoverPresentationControllerDelegate {
    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
        debugPrint(controller.description)
        return .Popover
    }

    func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
        let navController = UINavigationController.init(rootViewController: controller.presentedViewController)
        return navController 
    }
}
4

1 回答 1

3

尝试将演示文稿样式设置为工作表:

detailVC.modalPresentationStyle = UIModalPresentation.FormSheet
于 2016-04-03T16:57:36.177 回答