【发布时间】:2017-07-20 02:56:10
【问题描述】:
我有一个名为TestViewController 的主视图控制器,它有一个按钮,当您点击该按钮时,它会打开一个弹出视图控制器。当您点击背景时,弹出框会被关闭,这是我想要禁用的。我在我的弹出视图控制器中有这段代码,它应该运行但它没有运行。
extension TestViewController: UIPopoverPresentationControllerDelegate {
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
print ("TEST") //This does not show up in console
return false
}
}
编辑:
这是我用来打开弹出框的代码。
let popover = storyboard?.instantiateViewController(withIdentifier: "PopoverVC") as! PopOverViewController
popover.modalPresentationStyle = .popover
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
popover.dimView2 = self.dimView2
dimView2.isHidden = false
self.present(popover, animated: false)
}
【问题讨论】:
-
你设置了代理吗?发布您的代码
-
@Bilal 我更新了我的问题。
-
@Bilal 你说得对,我忘了加
popover.popoverPresentationController?.delegate = self as? UIPopoverPresentationControllerDelegate。如果您将其创建为答案,我会为您投票。