How to make UIPopoverPresentationController translucent for iOS 9

I used IB to create a segue to represent another popover view.

I added code in prepareForSegueto remove the UIPopoverPresentationControllerDelegate for the initial controller.

And I set the presentation style:

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController,
     traitCollection: UITraitCollection) -> UIModalPresentationStyle {
      return UIModalPresentationStyle.None
}

This gives me a nice standard popover.

However, I want to make a translucent popover.

I tried a couple of things:

  • I set the background color to IB for "cleaning"
  • I tried setting alpha in popover view
+4
source share
2 answers

To have a view controller on top of another with transparency, you need to return UIModalPresentationStyle.OverCurrentContext.

+5

: - , popover, 1.0, :

  • popover

    class MyVC: UIViewController, UIPopoverPresentationControllerDelegate {
    
  • alpha " segue" ( popover)

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let controller = segue.destination as! ISACGlossaryTVC
        controller.popoverPresentationController!.delegate = self
        self.view.alpha = 0.2;
    }
    
  • popoverPresentationControllerDidDismissPopover reset - , pop-over

    func popoverPresentationControllerDidDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) {
        self.view.alpha = 1.0;
    }
    
+1

Source: https://habr.com/ru/post/1615642/


All Articles