iPad上的UIPopoverPresentationController

时间:2016-04-03 16:43:01

标签: ios swift ipad uipopover uipresentationcontroller

我想在UIPopoverPresentationController中呈现一个viewController,就像iOS Setting App一样,当我们选择语言时。它在设备屏幕的中心呈现了一个viewController! enter image description here

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

enter image description here

这是我的代码:

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 
    }
}

1 个答案:

答案 0 :(得分:2)

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

detailVC.modalPresentationStyle = UIModalPresentation.FormSheet