How to hide status bar in UIImagepickercontroller?

前端 未结 13 1863
眼角桃花
眼角桃花 2020-11-30 02:55

I am new to iOS development. I am trying to hide status bar in UIImagePickerController. Whenever I click on \"Take photo\", status bar appears. It doesn\'t hide

相关标签:
13条回答
  • 2020-11-30 03:38

    The solution I found for applications build around : "View controller-based status bar appearance" set to YES

    I did add Category:

    //UIImagePickerController+StatusBarHidden.h
    #import <UIKit/UIKit.h>
    
    @interface UIImagePickerController (StatusBarHidden)
    @end
    
    //UIImagePickerController+StatusBarHidden.h
    #import "UIImagePickerController+StatusBarHidden.h"
    
    @implementation UIImagePickerController (StatusBarHidden)
    
    -(BOOL) prefersStatusBarHidden {
        return YES;
    }
    
    -(UIViewController *) childViewControllerForStatusBarHidden {
        return nil;
    }
    
    @end
    

    The method childViewControllerForStatusBarHidden is used rarely, but image picker do use it, thats why might cause some troubles

    You may also implement UIViewController singleton, with method which returns YES or NO, based on its property. Then your View controleller implements childViewControllerForStatusBarHidden returning the above singleton. Changing singleton property automatically change statusbar in app. There also is twin method childViewControllerForStatusBarStyle


    However for 2014, iOS8, see this https://stackoverflow.com/a/18960308/294884

    0 讨论(0)
  • 2020-11-30 03:41

    If you want to disable the status bar from plist, try this:

    1. Status bar is initially hidden : YES
    2. View controller-based status bar appearance : NO

    this is necessary for iOS 7, works for me. I do not know if there are some other techniques for doing this in iOS7. Set these two tags in your info.plist.

    Everytime your viewcontroller appears, in viewDidLoad or when image picker controller finishes , use this:

     - (void) imagePickerController:(UIImagePickerController *)picker1 didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
    {
       [[UIApplication sharedApplication] setStatusBarHidden:YES];
     .
     .
     .
     .
     }
    
    0 讨论(0)
  • 2020-11-30 03:42

    I used Silvertaurus's answer above, but with a little modification to the prefersStatusBarHidden method that I thought was very helpful:

    //UIImagePickerController+StatusBarHidden.h
    #import <UIKit/UIKit.h>
    
    @interface UIImagePickerController (StatusBarHidden)
    @end
    
    //UIImagePickerController+StatusBarHidden.h
    #import "UIImagePickerController+StatusBarHidden.h"
    
    @implementation UIImagePickerController (StatusBarHidden)
    
    -(BOOL) prefersStatusBarHidden {
        if (self.sourceType==UIImagePickerControllerSourceTypeCamera) {
            return YES;
        } else {
            return NO;
        }
    }
    
    -(UIViewController *) childViewControllerForStatusBarHidden {
        return nil;
    }
    
    @end
    

    This keeps the status bar up for the image picker when the camera is not displayed.

    0 讨论(0)
  • 2020-11-30 03:45

    Please try this.

    • Setting a delegate for the UIImagePickerController

    • hide the status bar in the delegate's navigationController:didShowViewController:animated: function.

    E.G:

    -(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
    {
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    }
    
    0 讨论(0)
  • 2020-11-30 03:50

    subclass UIImagePickerController ... mine is V1ImagePickerController ...

    .m file looks like this:

    #import "V1ImagePickerController.h"
    
    @interface V1ImagePickerController ()
    
    @end
    
    @implementation V1ImagePickerController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)   // iOS7+ only
        {
            self.edgesForExtendedLayout = UIRectEdgeNone;
    
            [self prefersStatusBarHidden];
            [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
        }
    }
    
    - (BOOL)prefersStatusBarHidden
    {
        return YES;
    }
    
    - (UIViewController *)childViewControllerForStatusBarHidden
    {
        return nil;
    }
    
    @end
    

    the childViewControllerForStatusBarHidden is the key!

    0 讨论(0)
  • 2020-11-30 03:50

    Try this

    [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];

    Also check this discussion.

    0 讨论(0)
提交回复
热议问题