【问题标题】:Statusbar overlapping on UIImagepickercontroller's Camera View in iOS 7 and iOS 8iOS 7 和 iOS 8 中 UIImagepickercontroller 的相机视图上的状态栏重叠
【发布时间】:2014-11-13 16:25:02
【问题描述】:

我使用 UIImagepickercontroller 拍照并选择现有照片,当相机视图出现时,相机的顶部被白色状态栏覆盖。如何删除状态栏或隐藏状态栏。他们中的许多人说它是一个 ios 7 错误,它已在 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];
   }

这个

 -(BOOL) prefersStatusBarHidden {
   return YES;
 }

这在委托中

 [UIApplication ShareApplication]SetStatusbarHidden:YES];

现在我正在使用 ios8,并且这种行为发生在所有 ios 版本中。 请帮帮我。

【问题讨论】:

  • 我遇到了同样的问题。在 iOS7 中,我通过继承 UIImagePickerController 并将 prefersStatusBarHidden 覆盖为 YES 来解决它。但在 iOS8 上它刚刚停止工作。如果您找到解决方案,请告诉我!

标签: ios7 uiimagepickercontroller ios8 statusbar overlapping


【解决方案1】:

实际上问题出在我的 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,它可以导航到所有其他类。

【讨论】:

    猜你喜欢
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    相关资源
    最近更新 更多