diff --git a/Classes/Popover.swift b/Classes/Popover.swift index d4169fd..1c9e531 100644 --- a/Classes/Popover.swift +++ b/Classes/Popover.swift @@ -218,10 +218,11 @@ open class Popover: UIView { } open func show(_ contentView: UIView, point: CGPoint, inView: UIView) { - if showBlackOverlay { - self.blackOverlay.autoresizingMask = [.flexibleWidth, .flexibleHeight] - self.blackOverlay.frame = inView.bounds + self.blackOverlay.autoresizingMask = [.flexibleWidth, .flexibleHeight] + self.blackOverlay.frame = inView.bounds + inView.addSubview(self.blackOverlay) + if showBlackOverlay { if let overlayBlur = self.overlayBlur { let effectView = UIVisualEffectView(effect: overlayBlur) effectView.frame = self.blackOverlay.bounds @@ -233,12 +234,10 @@ open class Popover: UIView { } self.blackOverlay.alpha = 0 } + } - inView.addSubview(self.blackOverlay) - - if self.dismissOnBlackOverlayTap { - self.blackOverlay.addTarget(self, action: #selector(Popover.dismiss), for: .touchUpInside) - } + if self.dismissOnBlackOverlayTap { + self.blackOverlay.addTarget(self, action: #selector(Popover.dismiss), for: .touchUpInside) } self.containerView = inView diff --git a/Example/Popover/ViewController.swift b/Example/Popover/ViewController.swift index 248202b..0acc57b 100644 --- a/Example/Popover/ViewController.swift +++ b/Example/Popover/ViewController.swift @@ -37,10 +37,7 @@ class ViewController: UIViewController { @IBAction func tappedLeftBottomButton(_ sender: UIButton) { let width = self.view.frame.width / 4 let aView = UIView(frame: CGRect(x: 0, y: 0, width: width, height: width)) - let options = [ - .type(.up), - .cornerRadius(width / 2) - ] as [PopoverOption] + let options: [PopoverOption] = [.type(.up), .cornerRadius(width / 2), .showBlackOverlay(false)] let popover = Popover(options: options, showHandler: nil, dismissHandler: nil) popover.show(aView, fromView: self.leftBottomButton) }