How to push SFSafariViewController?

前端 未结 2 1239
小鲜肉
小鲜肉 2021-02-05 08:13

2 strange things happen when I try to push Safari ViewController:

  1. Its adress bar with Done button is placed below my Navigation Bar;

  2. Delegate me

2条回答
  •  攒了一身酷
    2021-02-05 09:03

    In addition to rckoenes comment the only other option i see is to hide the navigation bar when presenting an SFSafariViewController

    import UIKit
    import SafariServices
    
    class ViewController: UIViewController {
        @IBAction func openBrowser(sender: AnyObject) {
            let safariViewController = SFSafariViewController(URL: NSURL(string: "http://your.url")!)
            safariViewController.delegate = self
    
            // hide navigation bar and present safari view controller
            navigationController?.navigationBarHidden = true
            navigationController?.pushViewController(safariViewController, animated: true)
        }
    }
    
    extension ViewController: SFSafariViewControllerDelegate {
        func safariViewControllerDidFinish(controller: SFSafariViewController) {
            // pop safari view controller and display navigation bar again
            navigationController?.popViewControllerAnimated(true)
            navigationController?.navigationBarHidden = false
        }
    }
    

提交回复
热议问题