在ios7之前,在AppDelegate裡用這行代碼就可以隱藏狀態欄:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
但是在ios7下,這行代碼不生效,需要先在項目的plist文件裡增加一個配置:
UIViewControllerBasedStatusBarAppearance
或者用圖形化頁面添加
View controller-based status bar appearance,設置為NO,效果是一樣的
配置瞭這個選項之後,上面那行代碼就可以隱藏status bar瞭
但是,如果應用裡用到瞭UIImagePickerController,在彈出照片選擇界面的時候,狀態欄又會跑出來,解決的辦法是:
先聲明Controller實現UINavigationControllerDelegate協議,然後設置為ImagePickerController的delegate
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self;
然後實現此方法:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { [[UIApplication sharedApplication] setStatusBarHidden:YES]; }
因為ImagePickerController是繼承自UINavigationController的