I study related iOS 7 status-Bar Maintain, but am I facing an issue while I am using UIImagePickerController
. Allow editing that Editing Window shows 20 pixels space at the top bar.
I used the code and first I set UIViewControllerBasedStatusBarAppearance
to NO
in info.plist
and set the delegate method:
@property (retain, nonatomic) UIWindow *background;
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 view controller that has no effect, so I put in my home viewController, one method for changing the background color of statusbar:
-(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 UIImagePickerController
allow editing window that shows it like this:
I tried with this solution for hide statusbar while present UIImagePickerController
:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
And show status bar code in ViewWillApear
.
I got this type of result:
Where am I doing wrong and how do I solve this?
Have a try with:
-(BOOL)prefersStatusBarHidden { return YES; }
It will hide the status bar.
On 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 hopes it will give you some hint.
Edited:
I found the problem.
This is the log the first time you show the homeViewController at 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 dismissing the imagePicker and call the 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 changed. That is the reason the status bar can't be shown.
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];
}];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With