SFSafariViewController没有正确解散(iOS 10.3)

时间:2017-06-28 00:42:42

标签: ios swift uiviewcontroller sfsafariviewcontroller

在我的应用中,我有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

1 个答案:

答案 0 :(得分:0)

当您关闭SFSafariViewController时,会触发svc的dismiss方法而不是您正在使用的ViewController。如果要覆盖SFSafariViewController的dismiss,则应该对其进行子类化并覆盖该子类中的dismiss func。 / p>