如何在UIView上关闭SFSafariViewController

问题描述 投票:1回答:1
class CustomScreen: UIView, SFSafariViewControllerDelegate {
@IBAction func webPageBtnAction(_ sender: Any) {
    if #available(iOS 9.0, *) {
        let svc = SFSafariViewController(url: NSURL(string: "https://stackoverflow.com/")! as URL)
        svc.delegate = self
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.window?.rootViewController = svc
    } else {
        // Fallback on earlier versions
    }
}

@available(iOS 9.0, *)
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
    controller.dismiss(animated: false, completion: nil)
}
}

在某些原因,我无法解雇SFSafariViewController。任何的想法?

swift uiwebview wkwebview uiwebviewdelegate sfsafariviewcontroller
1个回答
1
投票

因为在你的代码中你正在替换rootViewController(对于这种情况来说是一种不好的做法),你应该简单地介绍SFSafariViewController这样做:

let svc = SFSafariViewController(url: NSURL(string: "https://stackoverflow.com/")! as URL)
svc.delegate = self
UIApplication.shared.keyWindow?.rootViewController?.present(svc, animated: true, completion: nil)

据我所知,这是一个不好的做法,因为safariViewControllerDidFinish永远不会被调用,因为CustomScreen将被取代分配当前的rootViewController

© www.soinside.com 2019 - 2024. All rights reserved.