【发布时间】:2019-06-10 12:31:37
【问题描述】:
我有一个带有自定义按钮的自定义 UITabBarController。当我单击此按钮时,我打开 SFSafariViewController - 这里一切正常。但是当我点击SFSafariViewController 中的 "done" 按钮时,它会被关闭。但我无法返回UITabBarController,我只看到我在应用程序委托窗口中添加的背景颜色。
示例代码:
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?
【问题讨论】:
-
您需要实现
safariViewControllerDidFinish委托方法并实际关闭Safari视图控制器;您的标签栏控制器被“空”的 Safari 视图控制器隐藏。 -
这种方法应该怎么做? controller.dismiss(animated: true, completion: nil) 不起作用
-
为什么要在TabBarController中调用这个?如果您打算将此按钮添加到 tabor,那么答案可能会对您有所帮助,但否则,我将在 TabBarController 中设置一个 Viewcontroller 并在 ViewController 中创建此按钮和 SFSafariViewController。
-
补充一下,我发现更改 SafariVC 的
.modalPresentationStyle = .overCurrentContext实现了我想要的并且可能会帮助你,但我没有测试从 TabBarController 调用。
标签: ios swift uitabbarcontroller sfsafariviewcontroller sfsafariviewcontrollerdelegate