Skip to content

Commit

Permalink
Merge pull request #72 from corin8823/fix/show_black_overlay
Browse files Browse the repository at this point in the history
Fix not close when show black overlay is false
  • Loading branch information
corin8823 authored May 30, 2017
2 parents 4d178a5 + c9c08eb commit bf220f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
15 changes: 7 additions & 8 deletions Classes/Popover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions Example/Popover/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit bf220f1

Please sign in to comment.