简体   繁体   English

当提供自定义侧面菜单时,如何隐藏状态栏的一部分

[英]How to hide part of status bar, when custom side menu presented

I have a custom Side Menu class based on UIViewController . 我有一个基于UIViewController的自定义Side Menu类。 Presenting of Side menu looks like: Side menu呈现如下:

extension UIViewController: MenuPresentableProtocol {

    func setupMenu() {
        guard let menu = AppDelegate.shared.menu else { return }
        menu.view.frame = view.bounds
        view.addSubview(menu.view)
        menu.view.frame.origin.x = -UIScreen.main.bounds.width
    }

}

This means that the appearance of the status bar depends on the current ViewControllers prefersStatusBarHidden property, which in this case is false . 这意味着status barappearance取决于当前的ViewControllers prefersStatusBarHidden属性,在这种情况下为false

But I need to hide part of the status bar under the side menu . 但是我需要隐藏side menu下的status bar一部分。 Is there a way for implement this? 有没有办法实现这个?

This what I have: 这就是我所拥有的:

When menu hidden, it looks good. 当菜单隐藏时,它看起来不错。

在此输入图像描述

But when menu presents, ... 但是当菜单出现时,......

在此输入图像描述

PS I tried to use this answer , but it didn't help me. PS我尝试使用这个答案 ,但它没有帮助我。

Either you can hide the status bar fully OR you can show full. 您可以完全隐藏状态栏,也可以显示完整状态栏。 There is no way to hide part of status bar. 无法隐藏状态栏的一部分。

You can use the same background color as statusbar's textcolor in side menu and some opposite color on view controller. 您可以在侧边菜单中使用与状态栏的文本颜色相同的背景颜色,在视图控制器上使用相反的颜色。 In this case, statusbar's text color will have same color as your sidemenu's background color, it means that text will not be visible. 在这种情况下,状态栏的文本颜色将与侧面菜单的背景颜色具有相同的颜色,这意味着文本将不可见。 So, it will give effect that your half statusbar is hidden and half not. 因此,它将使您的半状态栏被隐藏而一半不被隐藏。

You will not find any single app on appstore with such case that you want, as it is not possible at all. 你不会在appstore上找到任何你想要的单一应用程序,因为它根本不可能。 If some app is looking to have same effect, then check its sidemenu's background color and statusbar's text color. 如果某个应用程序看起来具有相同的效果,请检查其侧面菜单的背景颜色和状态栏的文本颜色。 That both will be same. 两者都是一样的。

Answers are right, you cannot hide just a part of the status bar. 答案是对的,你不能只隐藏状态栏的一部分。 However you can give an almost-perfect illusion you do it by rebuilding your own statusbar clone and display it as you wish: iOS gives you the infos you need: 但是,您可以通过重建自己的状态栏克隆并按照您的意愿显示它来实现几乎完美的错觉:iOS为您提供所需的信息:

  • the time , 时间
  • your carrier name , 你的运营商名称
  • the battery level 电池电量
  • and battery charging state ... 和电池充电状态 ......
  • You will just miss the real cellular signal strength info, but you will then need to draw momentarily a fake one just for the time to present you menu and do your animation... 您将错过真正的蜂窝信号强度信息,但您需要暂时绘制一个假的,只是为了呈现菜单和动画...

At the end this is more an art work than hard coding :) 最后这是一个艺术作品而不是硬编码:)

This code snippet will actually hide your status bar with a view 此代码段实际上会使用视图隐藏您的状态栏

        UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 20)] autorelease];
        view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"PortraitNavigationBG"]]; 
        //or use same color as your background

        [self.navigationController.view addSubview:view];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM