开发者

Is there a way to prevent UIImagePickerController change statusbar style?

UIImagePickerController changes statusbar style to black/opaque. I want to keep status-bar style black/translucent. I'm finding a way to prevent status bar style changing. Or making it transited smoothly. Now, presenting UIImagePickerController changes status-bar style instantly, even -[presentModalViewController:picker animated:YES] specified.

Any开发者_如何学JAVA method, welcome, including hacking or private method. This is an app for AppStore, however I want to even try.


I wanted the status bar to remain black opaque while showing the photo library picker (the photo picker changes it to black translucent) and this solved the issue for me.

Set the UIImagePickerDelegate:

libraryUI.delegate = self;

Implement the following callback:

- (void)navigationController:(UINavigationController *)navigationController 
      willShowViewController:(UIViewController *)viewController 
                    animated:(BOOL)animated {

    if ([navigationController isKindOfClass:[UIImagePickerController class]] && 
        ((UIImagePickerController *)navigationController).sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO];
    }
}

You can specify any kind of status bar style in here. In your case, you would probably have to remove the sourceType check and specify UIStatusBarStyleBlackTranslucent.


Try this working perfectly on ios 8

-(void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    [[[viewController navigationController] navigationBar] setBarStyle:UIBarStyleBlack];
}


If you want to completely disable changing the status bar style, you could add a UIApplication category that blocks it.

@implementation UIApplication (MyCategory)
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle {}
@end

If that works, but you want to selectively disable changes, try subclassing UIApplication so you can call super when you want to pass the change through.


I found easier approach for me. Just do

[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self.delegate setNeedsStatusBarAppearanceUpdate];

and status bar is hidden (change code if you want it to be visible). Have to be called after picking image from UIImagePickerController.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜