2014-09-19 85 views
3

即時通訊使用UIImagepickercontroller拍攝照片並選擇現有照片,當相機視圖出現時,相機的頂部被白色狀態欄覆蓋。我如何刪除狀態欄或隱藏狀態欄。他們中的很多人說它是ios 7的bug,它已經在ios 7.1中修復了,但是我仍然面臨這個問題。iOS 7和iOS 8中UIImagepickercontroller相機視圖的狀態欄重疊

這是我的代碼,以顯示imagepickerController

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
imagePicker.delegate = (id)self; 
imagePicker.sourceType = (buttonIndex == actionSheet.firstOtherButtonIndex ? 

UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary); 
[self.viewController presentViewController:imagePicker animated:YES completion:nil]; 

此外,我試圖用下面的代碼隱藏狀態欄

- (void)navigationController:(UINavigationController *)navigationController  
    willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{ 
    [[UIApplication sharedApplication] setStatusBarHidden:YES]; 
    } 

-(BOOL) prefersStatusBarHidden { 
    return YES; 
} 

而這代表

[UIApplication ShareApplication]SetStatusbarHidden:YES]; 

現在我正在使用ios8,而這種行爲發生在所有ios版本中。 請幫我一把。

+1

我遇到同樣的問題。在iOS7中,我通過繼承UIImagePickerController並重寫prefersStatusBarHidden爲YES來解決它。但在iOS8上它停止工作。如果您找到解決方案,請告訴我! – hybridcattt 2014-09-30 16:15:20

回答

0

其實這個問題是在我的RootViewController的我創建使用的UIView一個狀態並設置其約束在橫向和縱向編程

- (void)setTopBar { 
if(topBar == nil && [[UIApplication sharedApplication] keyWindow] != nil) { 
    topBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)]; 
    topBar.backgroundColor = navController.view.backgroundColor; 
    topBar.tag = topBarViewTag; 
    UIView *containerView = [[UIApplication sharedApplication] keyWindow]; 
    [containerView addSubview:topBar]; 
    [containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view(20)]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:@{@"view" : topBar}]]; 
    [containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[view]|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:@{@"view" : topBar}]]; 
    [containerView layoutSubviews]; 
} 

}

所以,當我在viewWillAppear中評論說上面的方法,狀態欄不顯示,所以問題是與我的代碼。

如果有人面臨同樣的問題,我建議你看看你的RootViewcontroller,它可以導航到所有其他類。