我有一个带有自定义按钮的自定义UITabBarController
。当我单击此按钮时,我打开 SFSafariViewController - 这里一切正常。但是,当我单击 SFSafariViewController 中的“完成” 按钮时,它会关闭。但我无法返回 UITabBarController
,我只看到我在应用程序委托(delegate)窗口中添加的背景颜色。
示例代码:
class TabBar: UITabBarController, UITabBarControllerDelegate, SFSafariViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
}
func setupCenterButton() {
let centerButton = CenterButton(frame: CGRect(x: 0, y: 0, width: 74, height: 74))
centerButton.layer.cornerRadius = 37
centerButton.frame.origin.y = self.tabBar.frame.minY - 37
centerButton.frame.origin.x = view.bounds.width/2 - 37
centerButton.setImage(UIImage(named: "google"), for: .normal)
centerButton.addTarget(self, action: #selector(openURL), for: .touchUpInside)
view.addSubview(centerButton)
view.layoutIfNeeded()
}
@objc func openURL() {
let termsURL = SFSafariViewController(url: URL(string: "https://google.ru")!)
termsURL.modalPresentationStyle = .currentContext
termsURL.delegate = self
self.present(termsURL, animated: true, completion: nil)
}
}
如何在 SFSafariViewController
之后呈现 UITabBarController
?
最佳答案
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
//To access the Specific tabBar ViewController
let tabBarController = storyboard?.instantiateViewController(withIdentifier: "IdentifierTabbar") as! TabBar
// tabBarController.isComingFrom = "Settings" // Assign the Value
window?.rootViewController = tabBarController
}
关于ios - 从 UITabBarController 调用 SFSafariViewController 并在按下 "Done"后返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56526503/