iOS 7和iOS 8中UIImagepickercontroller相机视图上状态栏重叠问题

3

我使用UIImagepickercontroller拍照和选择现有照片,在相机视图出现时,相机顶部被白色状态栏遮盖。我该如何去除或隐藏状态栏?许多人都说这是iOS 7的一个bug,已经在iOS 7.1中修复了,但我仍然面临着这个问题。

这是我展示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];
   }

This

 -(BOOL) prefersStatusBarHidden {
   return YES;
 }

委托中的This关键字

 [UIApplication ShareApplication]SetStatusbarHidden:YES];

我现在正在使用ios8,而这种行为在所有ios版本中都会发生。 请帮助我解决这个问题。


1
我遇到了同样的问题。在iOS7中,我通过子类化UIImagePickerController并将prefersStatusBarHidden覆盖为YES来解决它。但是在iOS8上,它突然停止工作了。如果您找到了解决方案,请告诉我! - hybridcattt
1个回答

0
实际上问题出在我的根视图控制器上,我正在使用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,它作为导航到所有其他类的入口。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接