【问题标题】:How to dismiss SFSafariViewController on UIView如何在 UIView 上关闭 SFSafariViewController
【发布时间】:2018-08-10 10:28:12
【问题描述】:
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】:

    由于在您的代码中您要替换 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 的替换中被释放

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      相关资源
      最近更新 更多