我想删除屏幕顶部的状态栏.
这不起作用:
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) 我可以在我的应用中隐藏状态栏:
- (void)viewDidLoad{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[super viewDidLoad];
}
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.
通过查看类似问题的所有解决方案,我一直试图statusBar通过轻击手势来显示/隐藏.
我已经设置View controller-based status bar appearance = NO了plist.
我在我的DataViewController(页面视图控制器)和以下代码中尝试了以下代码RootViewController:
let app = UIApplication.sharedApplication()
app.setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.Fade)
Run Code Online (Sandbox Code Playgroud)
它不起作用.
这是嵌入一个UITabBarController,会有所作为吗?
此外,我能够得到以下内容来隐藏statusBar RootViewController:
override func prefersStatusBarHidden() -> Bool {
return true
}
Run Code Online (Sandbox Code Playgroud)
但DataViewController它甚至没有调用这个函数,只能以这种方式永久隐藏它,而不是打开/关闭它.
有任何想法吗?
我正在开发一个 swift 应用程序,当我在我的模态上使用全屏演示时,我找不到如何隐藏状态栏。
但是,我将这行代码放在我的 Modal View Controller 中:
override var prefersStatusBarHidden: Bool {
return true
}
Run Code Online (Sandbox Code Playgroud)
如果我创建一个不是模态的转场,或者如果我创建一个模态但不是全屏演示的转场,它就可以工作。
我在互联网上搜索如何解决它,我发现有人遇到了同样的问题,但没有解决方案。
此外,当我使用 Over Full Screen 选项时,我无法更改状态栏的颜色。我不明白为什么?我认为是有关系的。
谢谢你的帮助!