Problem with iOS 7 StatusBar when using UIImagePickerController Allow editing

I am studying the corresponding iOS 7 status byte, but I have to deal with the problem while I use UIImagePickerController . Allow editing This edit window shows 20 pixels of space on the top panel.

I used the code and first set the UIViewControllerBasedStatusBarAppearance to NO in info.plist and set the delegation method:

Appdelegate.h

 @property (retain, nonatomic) UIWindow *background; 

Appdelegate.m

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { [application setStatusBarStyle:UIStatusBarStyleLightContent]; self.window.clipsToBounds =YES; self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20); self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height); background = [[UIWindow alloc] initWithFrame: CGRectMake(0, 0, self.window.frame.size.width, 20)]; background.backgroundColor =[UIColor redColor]; [background setHidden:NO]; } 

In my home controller, which has no effect, so I put in my home viewController one method to change the background color in the status bar:

 -(void)viewWillLayoutSubviews{ if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { self.view.clipsToBounds = YES; CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenHeight = screenRect.size.height; self.view.frame = CGRectMake(0, 20, self.view.frame.size.width,screenHeight-20); self.view.bounds = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; if ([[NSUserDefaults standardUserDefaults] boolForKey:@"userIsMale"]) { [tempWindow setBackgroundColor:[UIColor colorWithRed:(46.0/255.0) green:(134.0/255.0) blue:(255.0/255.0) alpha:1]]; } else { [tempWindow setBackgroundColor:[UIColor colorWithRed:(246.0/255.0) green:(26.0/255.0) blue:(113.0/255.0) alpha:1]]; } [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } 

Now, when I present the UIImagePickerController to allow an editing window that shows this as follows:

Enter image description here

I tried to use this solution for a hidden status bar while UIImagePickerController is present:

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

And show the status code in ViewWillApear .

I got this result:

Enter image description here

Where am I doing wrong and how to solve it?

+6
source share
5 answers

Try:

 -(BOOL)prefersStatusBarHidden { return YES; } 

It will hide the status bar.

In iOS 7, if you want to use setStatusBarHidden: you need to set the View controller-based status bar appearance as NO in info.plist.

I hope this gives you some hint.


Edited by:

I found a problem.

This is the log when you first start homeViewController in viewWillAppear:

 (lldb) po [[UIApplication sharedApplication] windows] <__NSArrayM 0x8a74560>( <UIWindow: 0x8e33360; frame = (0 20; 320 548); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x8e348b0>; layer = <UIWindowLayer: 0x8e3c6e0>>, <UIWindow: 0x8c1db40; frame = (0 0; 320 20); gestureRecognizers = <NSArray: 0x8c1e170>; layer = <UIWindowLayer: 0x8c1da80>> ) 

And this is the log after rejecting imagePicker and calls viewWillAppear:

 (lldb) po [[UIApplication sharedApplication] windows] <__NSArrayM 0x8c1a700>( <UIWindow: 0x8e33360; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x8e348b0>; layer = <UIWindowLayer: 0x8e3c6e0>>, <UIWindow: 0x8c1db40; frame = (0 0; 320 20); gestureRecognizers = <NSArray: 0x8c1e170>; layer = <UIWindowLayer: 0x8c1da80>>, <UITextEffectsWindow: 0x8c53380; frame = (0 0; 320 568); hidden = YES; opaque = NO; gestureRecognizers = <NSArray: 0x8c538a0>; layer = <UIWindowLayer: 0x8c53520>> ) 

The default window size has changed. For this reason, the status bar cannot be displayed.

I edited your code like this and it works for me:

  - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // [[UIApplication sharedApplication] setStatusBarHidden:YES]; if(OVER_IOS7){ [self.navigationController.navigationBar setTranslucent:NO]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide]; } -(void)viewWillLayoutSubviews{ if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { self.view.clipsToBounds = YES; CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenHeight = screenRect.size.height; self.view.frame = CGRectMake(0, 20, self.view.frame.size.width,screenHeight-20); self.view.bounds = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); UIWindow *defaultWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:0]; defaultWindow.frame = CGRectMake(0,20,320,548); defaultWindow.bounds = CGRectMake(0,20,320,548); UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; if ([[NSUserDefaults standardUserDefaults] boolForKey:@"userIsMale"]) { [tempWindow setBackgroundColor:[UIColor colorWithRed:(46.0/255.0) green:(134.0/255.0) blue:(255.0/255.0) alpha:1]]; } else { [tempWindow setBackgroundColor:[UIColor colorWithRed:(246.0/255.0) green:(26.0/255.0) blue:(113.0/255.0) alpha:1]]; } [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } } - (IBAction)showImagePicker:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; [picker setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum]; [self presentViewController:picker animated:YES completion:^{ [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; }]; } 
+3
source

Try submitting a UIImagePickerController :

 UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; [tempWindow.rootViewController presentViewController:myImgPickerController animated:YES completion:nil]; 

I don’t know if this will help you, but you can try ... :)

Another option is when you present a UIImagePickerController . At this time, set the view frame as it was at the beginning, and also hide the status bar ...

0
source

I also ran into the same problem, but there is only one way to overcome it.

Go to the info.plist file and set the option “View status bar based on controller” to “NO”.

0
source

I had a similar problem, but when I return from the camera to my UIViewController. I solved the problem with the following code in the controller that clicks UIImagePickerController:

First i open picker

 - (void)showPhotoPicker:(UIImagePickerControllerSourceType)sourceType { [self.picker setSourceType:sourceType]; [self presentViewController:self.picker animated:YES completion:nil]; } 

I save the status bar without any problems, I saw that some people have problems with this, I do not

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

It’s very important to call up a completion matching layout

 // Apply photo selected -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [self.enterPicture setImage:info[UIImagePickerControllerEditedImage]]; [picker dismissViewControllerAnimated:YES completion:^(void){[self.view setNeedsLayout];}]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker dismissViewControllerAnimated:YES completion:^(void){[self.view setNeedsLayout];}]; } 

And here is the magic:

 // fix the status bar & navigation bar after close the photo album on IOS7 -(void)viewWillLayoutSubviews { UINavigationBar *navBar= [[self navigationController] navigationBar]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7 && navBar) { CGFloat statusBarHeight = [[UIApplication sharedApplication] isStatusBarHidden] ? 0.0f : 20.0f; [navBar setFrame:CGRectMake(0, statusBarHeight, navBar.frame.size.width, navBar.frame.size.height)]; [self.view setBounds:CGRectMake(0, (statusBarHeight + navBar.frame.size.height) * -1, self.view.bounds.size.width, self.view.bounds.size.height)]; } } 
0
source

Just add a controller:

 - (void)viewWillAppear:(BOOL)animated { [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide]; } 
0
source

All Articles