How to introduce PopOver in iOS9

I am trying to create a popup, and when I present the view controller, the background is always solid black and the size is full.

I can’t understand what happened, and here is the code that I have

@IBAction func distancePopOver( sender : UIBarButtonItem){ //a UIViewController that I created in the storyboard let controller = storyboard!.instantiateViewControllerWithIdentifier("distancePopOver") controller.modalPresentationStyle= UIModalPresentationSTyle.PopOver controller.preferredContentSize = CGSizeMake(200,30) self.presentViewController(controller, animated: true, completion: nil) //Configure the Popover presentation controller let popController = (controller.popoverPresentationController)! popController.permittedArrowDirections = UIPopoverArrowDirection.Down popController.barButtonItem = sender popController.delegate = self } 

Whenever I click on a UIBarButtonItem element, it displays the view in full screen mode, but should it not be listed on line 5?

+7
ios swift
source share
1 answer

Poppors are now pretty thin. First, you will want to configure the popoverPresentationController before you submit it.

Second, make sure that the direction of the arrow indicates how the arrow points, and not where the content corresponds to UIBarButtonItem. So, if it's inside the UIToolbar (and is near the bottom of the screen), you will want .Down otherwise, if its navigation bar (at the top) you want to use .Up .

 @IBAction func distancePopOver( sender : UIBarButtonItem){ //Configure the Popover presentation controller let popController = (controller.popoverPresentationController)! popController.permittedArrowDirections = .Down // .Up popController.barButtonItem = sender popController.delegate = self //a UIViewController that I created in the storyboard let controller = storyboard!.instantiateViewControllerWithIdentifier("distancePopOver") controller.modalPresentationStyle = .Popover controller.preferredContentSize = CGSizeMake(200,30) presentViewController(controller, animated: true, completion: nil) } 

Now, if you have gone this far and still not working, this is because the default behavior in the compact class is to fill the screen. Since you already set your view manager as a popover delegate, you just need to implement this delegate function: adaptivePresentationStyleForPresentationController(_:traitCollection:) and return .None for the presentation style. This will even allow you to show a real look on the iPhone. See My Blog Post: iPhone Popover for a full example of this.

+1
source share

All Articles