我有一個正在調用的彈出窗口,我想要關閉彈出窗口的唯一方法是通過單擊關閉按鈕,而不是通過背景上的磁帶。目前,我的代碼啓動酥料餅是這樣的: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