2014-04-29 49 views
0

我使用以下代碼在appDelegate類中創建了我的狀態欄。在AppDelegate實現後隱藏自定義狀態欄視圖

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

現在我想動態地將它隱藏在viewCOntrollers之一中。我隱藏了導航欄和狀態欄。

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

我可以看到狀態欄已被隱藏,因爲所有文本都隱藏了,但只是灰色的視圖不會隱藏。

和問題範圍的iOS 7

回答

1

通過調用[[UIApplication sharedApplication] setStatusBarHidden:YES];隱藏本機應用程序狀態欄是UIStatusBar類的實例。但它並不隱藏你的自定義視圖statusBarView,它是UIView類的實例。
隱藏自定義視圖電話:
statusBarView.hidden = YES;

[statusBarView removeFromSuperView]

如果您需要將其從ViewController中隱藏,則考慮將屬性添加到AppDelegate以存儲statusBarView並從任何其他位置訪問它。

+0

好主意。讓我快速嘗試一下。 – CalZone

+0

如果我創建了一個屬性AppDelegate,並在我的VC中創建了一個Appdelegate對象,如下所示:'AppDelegate * delegateObj =(AppDelegate *)[[UIApplication sharedApplication] delegate];'。我無法訪問自定義屬性。你能否澄清我需要如何在應用程序委託類中創建屬性? – CalZone

+0

@CalZone,你需要在AppDelegate.h文件中設置屬性:'@property(nonatomic,readonly,strong)UIView * statusBarView;'用於訪問它:'delegateObj.statusBarView'。 –