I want to present a viewController in UIPopoverPresentationController like iOS Setting App do when we choose language. It presents a viewController at center of device screen!
But, my result is not like that!
This is my code:
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)
}
And the delegate:
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
}
}
Try setting the presentation style to sheet:
detailVC.modalPresentationStyle = UIModalPresentation.FormSheet