ios - 从 UITabBarController 调用 SFSafariViewController 并在按下 "Done"后返回

标签 ios swift uitabbarcontroller sfsafariviewcontroller sfsafariviewcontrollerdelegate

我有一个带有自定义按钮的自定义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/

相关文章:

ios - 无法为此找到正确的日期格式 (NSDateFormatter)

ios - React Native iOS pod 设置有重复的目标问题

ios - swift 3 : thumbnail from video

ios - Xcode 不会打开 ContentViewController 但会停留在启动屏幕上

swift - Realm 相同线程的NotificationToken观察commitWrite(没有通知: [token])

ios - 在 'window' 类型的对象上找不到属性 'CustomTabBar'

iphone - 删除 UITableViewCell 和该单元格的所有数据

ios - Swift iOS 图表 - 隐藏某些条形图值标签

swift - 按下 'more' 按钮时如何设置标签栏 Controller 内的导航栏颜色和单元格大小?

ios - 使标签栏按钮打开右侧菜单