I used IB to create a segue to present another view a popover.
I added a code in prepareForSegue
to deletage UIPopoverPresentationControllerDelegate to initial controller.
And I set 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 semi-transparent popover.
I tried couple of things:
To have a view controller on top of another with transparency, you'll need to return UIModalPresentationStyle.OverCurrentContext
.
Concept: adjust the alpha value of the source view controller before segueing to the popover, and back to 1.0 again when it has been dismissed:
Set the source view controller as a popover delegate
class MyVC: UIViewController, UIPopoverPresentationControllerDelegate {
Set the delegate and source view alpha in the 'prepare for segue' function (on the way to the popover)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let controller = segue.destination as! ISACGlossaryTVC
controller.popoverPresentationController!.delegate = self
self.view.alpha = 0.2;
}
Create delegate method popoverPresentationControllerDidDismissPopover , and reset the source view alpha back when the pop-over has been dismissed
func popoverPresentationControllerDidDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) {
self.view.alpha = 1.0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With