我能够让我的应用程序通过SFSafariViewController根据这个post自动加载一个url,它工作的很好,唯一的缺点是导航栏。SFSafariViewController:隐藏导航栏
当以这种方式使用SFSafariViewController导航栏时,这种方式毫无用处,因为url是只读的,'done'链接除了重新加载页面外没有其他任何操作。因此,我想完全隐藏导航栏。
根据接受的答案附带的评论,有人建议将我的根视图控制器设置为SFSafariViewController,我无法工作。设置很简单,因为有一个视图控制器,其代码包含在上述文章中。
如何隐藏导航栏,但仍然保持SFSafariViewController的好处?或者,如果我无法隐藏导航栏,至少隐藏“完成”链接?
代码片段:
import UIKit
import SafariServices
class ViewController: UIViewController
{
private var urlString:String = "https://example.com"
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(animated: Bool)
{
super.viewDidAppear(animated)
let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!)
self.presentViewController(svc, animated: true, completion: nil)
self.navigationItem.rightBarButtonItem = nil
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
-----作品。导航栏“隐藏” -----
import UIKit
import SafariServices
class ViewController: UIViewController
{
private var urlString:String = "https://example.com"
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// This will remove the status (battery, time, etc) bar
UIApplication.sharedApplication().statusBarHidden = true
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!)
// Kind of a hack, in that we really aren't removing the navbar
// Rather we are adjusting the starting point of the vpc object so it appears as the navbar is hidden
self.presentViewController(svc, animated: true) {
var frame = svc.view.frame
let OffsetY: CGFloat = 42
frame.origin = CGPoint(x: frame.origin.x, y: frame.origin.y - OffsetY)
frame.size = CGSize(width: frame.size.width, height: frame.size.height + OffsetY)
svc.view.frame = frame
}
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// For this to work be sure to set the following setting to OFF, in info.plist
// 'View controller-based status bar appearance'
override func prefersStatusBarHidden() -> Bool {
return true
}
}
你可以继承'SFSafariViewController'并将导航栏隐藏在'viewWillAppear:'? – JAL
我可以尝试......我是helio newb在ios开发,所以任何代码片段都会帮助。 –
你可以尝试像这样:'self.navigationItem.rightBarButtonItem = nil' –