在我的应用中,我有SFSafariViewController
我正在以模态显示。解雇后,呈现的ViewController没有调用其dismiss
方法。我的子类UIViewController
的代码:
override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
print("will present")
super.present(viewControllerToPresent, animated: flag) {
completion?()
print("did present")
}
}
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
print("will dismiss)")
super.dismiss(animated: flag) {
completion?()
print("did dismiss")
}
}
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
print("finished with \(controller)")
}
func testSVC() {
let svc = SFSafariViewController(url: URL(string: "https://www.stackoverflow.com")!)
svc.delegate = self
self.present(svc, animated: true) {
print("presented \(svc)")
}
}
在SafariViewController中调用testSVC()
然后点击“完成”会产生以下输出:
will present
presented <SFSafariViewController: 0x7fd981b2f200>
did present
finished with <SFSafariViewController: 0x7fd981b2f200>
就是这样。缺少dismiss
个打印语句。任何人都可以帮我弄清楚为什么没有调用dismiss
?我认为所有UIViewController
解雇都被转发给了呈现UIViewController
。
答案 0 :(得分:0)
当您关闭SFSafariViewController时,会触发svc的dismiss方法而不是您正在使用的ViewController。如果要覆盖SFSafariViewController的dismiss,则应该对其进行子类化并覆盖该子类中的dismiss func。 / p>