在ios7之前,在AppDelegate裡用這行代碼就可以隱藏狀態欄:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
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]; }