【发布时间】:2017-07-19 18:03:41
【问题描述】:
我有一个正在调用的弹出框,我希望关闭弹出框的唯一方法是单击“关闭”按钮,而不是点击背景。目前我启动弹出框的代码是这样的:
let popover = storyboard?.instantiateViewController(withIdentifier: "PopoverVC") as! PopOverViewController
popover.modalPresentationStyle = .popover
popover.popoverPresentationController?.delegate = self as? UIPopoverPresentationControllerDelegate
popover.popoverPresentationController?.sourceView = self.view
popover.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
popover.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
popoverPresentationController?.passthroughViews = nil
dimView.isHidden = false
popover.dimView = self.dimView
self.present(popover, animated: false)
我在背景中有一个 UIview,当弹出框出现时我用来使背景变暗,但是当您点击背景时,它会关闭弹出框。如何保持弹出窗口打开?我认为popoverPresentationController?.passthroughViews = nil 应该可以解决这个问题,但它没有。
编辑:
添加我的 PopOverViewController 类:
class PopOverViewController: UIViewController, UIPopoverPresentationControllerDelegate {
var dimView:UIView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
print ("test")
return false
}
@IBAction func closeButton(_ sender: Any) {
self.dismiss(animated: false, completion: nil)
dimView?.isHidden = true
}
}
【问题讨论】:
-
我们可以看看你的 PopOverViewController 类吗?
-
我将其添加到问题中。