How to hide status bar in UIImagepickercontroller?

前端 未结 13 1865
眼角桃花
眼角桃花 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:50

    You can do it with a category:

    @interface UIImagePickerController (HideStatusBar)
    
    @end
    
    
    @implementation UIImagePickerController (HideStatusBar)
    
    - (BOOL)prefersStatusBarHidden
    {
        return YES;
    }
    
    - (UIViewController *)childViewControllerForStatusBarHidden
    {
        return nil;
    }
    
    @end
    

    Source: https://gist.github.com/psobko/9493473

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

    I had an issue where in iOS7 my status bar was not being hidden. I hid it programmatically and it still displayed in iOS7, but when ran in iOS6 the status bar would hide appropriately. You have to go to the plist and add the following:

    'view controller-based status bar appearance' and set to NO.

    If you want the status bar to re-appear in other view controllers and only be hidden on a particular VC, then you set the status bar to hidden YES when the VC loads. When the VC will disappear you set the status bar hidden back to NO.

    - (void)viewDidLoad
    {
    
        [super viewDidLoad];
        [[UIApplication sharedApplication] setStatusBarHidden:YES];
    
    }
    

    and when the controller will disappear you add the following to set the status bar so it is no longer hidden and will display on the next View:

    -(void)viewWillDisappear:(BOOL)animated{
    
         [[UIApplication sharedApplication] setStatusBarHidden:NO];
    
    }
    

    setStatusBarHidden:withAnimation: if you want some smooth animation

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

    i think i solved this in a pretty simple way without subclassing and using plist. it only hides for UIImagePickerController.

    this example is for bringing up the photo gallary only, but i imagine you can apply it in the same way to anywhere with in uiimagepickercontroller

    - (void)showGallary
    {
      [CATransaction begin];
      [CATransaction setCompletionBlock:^{
          [[UIApplication sharedApplication] setStatusBarHidden:YES];
          [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
      }];
    
      imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    
      [CATransaction commit];
    }
    
    0 讨论(0)
  • 2020-11-30 03:56

    Try my answer posted here if you want to keep using ViewController-Based Status Bar Appearance.

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

    In my case I had to use presentViewController to show UIImagePickerViewController (iOS7).

    1- Set View controller-based status bar appearance to NO in .plist 2- Create a category for UIImagePickerController and in viewDidLayoutSubviews:

    - (void)viewDidLayoutSubviews{
        [super viewDidLayoutSubviews];
        [[UIApplication sharedApplication] setStatusBarHidden:YES];
    }
    

    3- Added the two following methods to the category:

    - (BOOL)prefersStatusBarHidden{
        return YES;
    }
    
    - (UIViewController *)childViewControllerForStatusBarHidden{
        return nil;
    }
    

    I hope this will help.

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

    This worked fine for me:

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

    Edit: As of today i just found out that in your info.plist, if you just copy-paste view controller-based status bar appearance there it won't work ... you have to hit enter on a property, and scroll to the last one of them so you will have autocomplete to :view controller-based status bar appearance and an boolean, with no. I tried multiple times but it does not work just copying. Have a nice day.

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