【问题标题】:Hiding custom status bar view after implementation in AppDelegate在 AppDelegate 中实现后隐藏自定义状态栏视图
【发布时间】:2014-06-16 02:12:27
【问题描述】:

我在 appDelegate 类中使用以下代码创建了状态栏。

   UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320, 20)];
        theView.backgroundColor = customGrayColor;
        [self.window.rootViewController.view addSubview:statusBarView];

现在我想将它动态隐藏在其中一个 viewCONtroller 中。我隐藏了导航栏和状态栏。

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [self.navigationController setNavigationBarHidden:YES];

我可以看到状态栏已隐藏,因为所有文本都隐藏了,但只有灰色视图没有隐藏。

而且问题范围仅限于 iOS 7。

【问题讨论】:

    标签: objective-c ios7 statusbar


    【解决方案1】:

    通过调用[[UIApplication sharedApplication] setStatusBarHidden:YES];,您可以隐藏作为UIStatusBar 类实例的本机应用程序状态栏。但它不会隐藏您的自定义视图statusBarView,即UIView 类的实例。
    隐藏自定义视图调用:
    statusBarView.hidden = YES;

    [statusBarView removeFromSuperView]

    如果您需要对ViewController 隐藏它,请考虑将属性添加到AppDelegate 以存储statusBarView 并从任何其他地方访问它。

    【讨论】:

    • 好主意。让我快速尝试一下。
    • 如果我创建了一个属性 AppDelegate,并在我的 VC 中创建了一个 Appdelegate 对象,如下所示:AppDelegate *delegateObj = (AppDelegate *)[[UIApplication sharedApplication] delegate];。我无法访问自定义属性。你能澄清我需要如何在应用委托类中创建属性吗?
    • @CalZone,您需要在 AppDelegate.h 文件中设置属性,例如:@property (nonatomic, readonly, strong) UIView *statusBarView; 访问它使用:delegateObj.statusBarView
    • 搞定了。我的问题是我使用的是@class Appdelegate; 而不是#import Appdelegate。谢谢你。我会将其标记为答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    • 1970-01-01
    • 2016-11-24
    • 2016-09-04
    相关资源
    最近更新 更多