The Nomad The Nomad - 1 year ago 94
iOS Question

UIPopoverPresentationController displaying popover as full screen

I am trying to use

to display a
that doesn't take up the whole screen. I've followed many different tutorials with no luck.

Here is my code. It correctly instantiates the
, but it takes up the entire screen instead of just a smaller screen as I defined in

func showPopover() {
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("PopupTimePickerViewController") as PopupTimePickerViewController
vc.modalPresentationStyle = .Popover
vc.preferredContentSize = CGSizeMake(200, 100)

if let presentationController = vc.popoverPresentationController {
presentationController.delegate = self
presentationController.permittedArrowDirections = .Up
presentationController.sourceView = self.view
presentationController.sourceRect = CGRectMake(0, 0, 50, 50)

self.presentViewController(vc, animated: true, completion: nil)

Answer Source

In iPhone, you should add the following in order to present a popover.

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!) -> UIModalPresentationStyle {
    // Return no adaptive presentation style, use default presentation behaviour
    return .None
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download