0

我有一个自UITabBarController定义按钮。当我单击此按钮时,我会打开SFSafariViewController- 这里一切正常。但是当我点击“完成”按钮时,SFSafariViewController它会被关闭。但我无法返回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)
    }
}

UITabBarController之后我该如何呈现SFSafariViewController

4

2 回答 2

0
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
}
于 2019-06-10T13:16:05.820 回答
0

我遇到了同样的问题,当我在 SafariViewController 上点击“完成”时,我以编程方式解决了选择另一个标签栏项目的问题。在我的示例中,我选择标签栏的第一项。

import UIKit
import SafariServices
    
class WebViewController: UIViewController, SFSafariViewControllerDelegate {
        
    override func loadView() {

    }
    override func viewDidLoad() {
        super.viewDidLoad()
        guard let url = URL(string: "<your website url>") else {
            return
        }

        let safariVC = SFSafariViewController(url: url)
        present(safariVC, animated: true, completion: {self.selectFirstTab()})
        
    }
    
    func selectFirstTab(){
        self.tabBarController?.selectedIndex = 0
    }

}
于 2020-07-19T18:22:38.250 回答