我已经成功通过SFSafariViewController使我的应用程序自动加载了一个url,参考post。它的工作非常出色,但唯一的缺点是导航栏。
使用这种方式时,SFSafariViewController的导航栏有些无用,因为url是只读的,而“完成”链接除了重新加载页面外没有其他作用。 因此,我想完全隐藏导航栏。
根据接受答案所附的评论建议,建议将我的根视图控制器设置为SFSafariViewController,但我无法让其运行。 这个设置很简单,因为只有一个视图控制器,其中包含上述帖子中的代码。
如何隐藏导航栏,但仍然保持SFSafariViewController的好处? 或者,如果我无法隐藏导航栏,至少可以隐藏“完成”链接吗?
代码片段:
使用这种方式时,SFSafariViewController的导航栏有些无用,因为url是只读的,而“完成”链接除了重新加载页面外没有其他作用。 因此,我想完全隐藏导航栏。
根据接受答案所附的评论建议,建议将我的根视图控制器设置为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:
中隐藏导航栏吗? - JALself.navigationItem.rightBarButtonItem = nil
。 - Craig Otis