UIPopoverPresentationController displaying popover as full screen

For Swift3/IOS10, looks like we need to do some thing like

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle
{
    return .none
}

Adding this answer, in case, someone runs into this problem as i did when migrating to swift3/IOS10


For Swift3+/IOS10+, when dealing with iPhone:

You must add UIPopoverPresentationControllerDelegate the delegate at:

class YourClass:  UIViewController, UIPopoverPresentationControllerDelegate { ...

Then implement in this same parent class (which will show the popover) the method below.

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle
{
    return .none
}

And then set the popover configuration below:

myPopover.modalPresentationStyle = .popover
myPopover.popoverPresentationController?.sourceRect = VIEWTOPOINTTHEARROW.frame
myPopover.popoverPresentationController?.sourceView = self.view
myPopover.popoverPresentationController?.delegate = self

Also you may set some configuration for the popover class

 class MyPopover: UIViewController {

 override func viewDidLoad() {
    super.viewDidLoad()
    //popover size
    self.preferredContentSize = CGSize(width: 320, height: 200) 
    //sets the arrow of the popover to same color of background
    self.popoverPresentationController?.backgroundColor = self.view.backgroundColor
   }

 }

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
}