我有一个正在调用的弹出窗口,我想要关闭弹出窗口的唯一方法是通过单击关闭按钮,而不是通过背景上的磁带。目前,我的代码启动酥料饼是这样的:Swift Popover关闭时触摸背景
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当酥料饼的出现,但是当你在后台挖掘,它将关闭酥料饼。我怎样才能让popover保持开放状态?我认为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类吗? –
我将它添加到问题中。 – Martheli