UIImagePickerController打破状态栏外观

Ale*_*x L 137 ios7

在我的.plist文件中,我将" 查看基于控制器的状态栏外观 "设置为NO.但之后UIImagePickerController,我的应用程序就像选项设置为一样YES.

在我的应用程序中,我提出了一个VC UIImagePickerController.

问题是这样的:

  • 显示照片选择器后,当选择照片库时,状态栏文本的颜色会发生变化.
  • 然后,一旦UIImagePickerController被解除,我的应用程序的其余部分的状态栏间距会发生变化,其他控制器的所有导航栏都会显示在状态栏下.

有没有办法解决这个问题而不管理视图控制器中的状态栏?

dpj*_*nes 192

以上解决方案都不适合我,但通过结合Rich86man和iOS_DEV_09的答案,我得到了一个始终如一的解决方案:

UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
Run Code Online (Sandbox Code Playgroud)

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

关于这个很棒的解决方案.对于2014/iOS8,我发现在某些情况下你还需要包括prefersStatusBarHidden,可能还有childViewControllerForStatusBarHidden......

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

-(BOOL)prefersStatusBarHidden   // iOS8 definitely needs this one. checked.
    {
    return YES;
    }

-(UIViewController *)childViewControllerForStatusBarHidden
    {
    return nil;
    }

-(void)showCamera
    {
    self.cameraController = [[UIImagePickerController alloc] init];
    self.cameraController.delegate = (id)self; // dpjanes solution!
    etc...
Run Code Online (Sandbox Code Playgroud)

希望它可以帮助某人

  • 这是诀窍(正如Rich86man所说):"由于UIImagePickerController是一种导航控制器,你也将自己设置为UINavigationController委托." (3认同)
  • 虽然状态栏以非常不稳定的方式弹出和弹出,但这仍然有效.我向Apple提交了一个错误. (3认同)
  • 解雇UIImaegPicker后怎么样?我设置状态栏隐藏假,然后它的背景变黑. (2认同)

Ric*_*man 84

我今天遇到了同样的问题.这是我的解决方案.

在调用图像选择器的视图控制器中,将您自己设置为图像选取器的委托.(你可能已经这样做了)

UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
Run Code Online (Sandbox Code Playgroud)

由于UIImagePickerController是一种导航控制器,因此您也将自己设置为UINavigationController委托.然后 :

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Run Code Online (Sandbox Code Playgroud)

将UIStatusBarStyleLightContent替换为您要查找的任何样式.


小智 10

如果您在.plist文件中将"基于控制器的状态栏状态显示"设置为"否",则接受的答案将起作用.如果确实需要控制某些其他视图控制器中的状态栏并将此选项设置为YES,则使UIImagePickerController正常运行的另一种方法是通过子类化

// .h
@interface MYImagePickerController : UIImagePickerController
@end

// .m
@implementation MYImagePickerController
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent; // change this to match your style
}
@end
Run Code Online (Sandbox Code Playgroud)


iOS*_*DEV 6

我遇到了同样的问题.

这是我的解决方案.把它放在视图控制器的viewWillAppear中,从中打开图像选择器视图

-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];

[[UIApplication sharedApplication] setStatusBarHidden:YES];

}
Run Code Online (Sandbox Code Playgroud)