我想删除屏幕顶部的状态栏.
这不起作用:
func application
(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: NSDictionary?)
-> Bool
{
application.statusBarHidden = true
return true
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
func application
(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: NSDictionary?)
-> Bool
{
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var controller = UIViewController()
application.statusBarHidden = true
controller.setNeedsStatusBarAppearanceUpdate()
var view = UIView(frame: CGRectMake(0, 0, 320, 568))
view.backgroundColor = UIColor.redColor()
controller.view = view
var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
label.center = CGPointMake(160, 284)
label.textAlignment = NSTextAlignment.Center
label.text = "Hello World"
controller.view.addSubview(label)
self.window!.rootViewController = controller
self.window!.makeKeyAndVisible()
return …Run Code Online (Sandbox Code Playgroud) 我经常隐藏状态栏
override func prefersStatusBarHidden() -> Bool {
return true
}
Run Code Online (Sandbox Code Playgroud)
但Xcode给了我一个错误,说"方法不会覆盖其超类中的任何内容".
如果我删除了override,Xcode会给出一个不同的错误:"方法"prefersStatusBarHidden()'与Objective-C选择器'prefersStatusBarHidden'与来自超类'UIViewController'的'prefersStatusBarHidden'的getter冲突与同一个Objective-C选择器"
我还在Target的常规设置中选中了"隐藏状态栏":
但状态栏仍然显示.
我在另一个Stack Overflow答案中找到了这个方法
UIApplication.shared.setStatusBarHidden(true, with: .none)
Run Code Online (Sandbox Code Playgroud)
但这也不会隐藏状态栏.
在Xcode 8 Beta 1中,我使用了第一种和第二种方法,它们可以隐藏状态栏(第一种方法没有返回错误).现在我可以用Xcode 8 Beta 4隐藏状态栏吗?
注意:状态栏显示在模拟器设备和物理设备上,均运行iOS 10.