So my app has the status bar set to be hidden like this in the AppDelegate. And it works as intended.
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Then I use UIDocumentInteractionController's presentPreviewAnimated like this,etc.:
[self.docInteractionController presentPreviewAnimated:YES];
I observed that the status bar does show up (with battery info etc.) while in this UIDoc's preview mode. But after dismissing the preview and back to the original view, while the status bar is not there but there is a black bar instead. The size is same as the status bar.
Has anyone encountered this behavior and any remedy for this?
I am facing the same issue. Found a quick fix to this issue...set the view's frame back inside viewWillAppear... My code looks something like this...
-(void)viewWillAppear:(BOOL)animated {
... //other settings
self.view.frame = [[UIApplication sharedApplication].keyWindow bounds];
}
Hope it helps! :)
Related
I know this question has been asked several times and the solutions I have seen have been very helpful. But since i have 2 conflicting requirements, I am a little stranded and hoping to find some help.
So here are the requirements:
We have multiple View controllers out of which only one needs to be full screen (without status bar on the top).
The other view controllers need to show a black status bar with a dark gray navigation bar
The First View controller is embedded in a navigation controller.
As recommended in some of the other posts, I did the following
Set UIViewControllerBasedStatusBarAppearance to NO
Added this code in app delegate
CGRect frame = [[UIScreen mainScreen] bounds];
self.window.frame = CGRectMake(0,20,frame.size.width, frame.size.height-20);
self.window.bounds = self.window.frame;
It works fine if I only stay in those View controllers that have the status bar.
The moment I open the FULL screen view controller, that VC is cut off on the top as shown here.
Additionally when I come back to the Main view controller, now thats shifted up as well and the title bar is where the status bar was showing.
I have tried to push the views back down by resetting the view.frame and requesting layout but it doesnt take effect.
Any suggestions on how to resolve this?
Don't change self.window.bounds in app delegate. Instead, in your view controllers try something like this:
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES/NO animated:YES];
[self setNeedsStatusBarAppearanceUpdate]; // For showing/hiding status bar
[super viewWillAppear:animated];
}
- (BOOL)prefersStatusBarHidden {
return YES/NO;
}
You will have different frames for the view in ViewDidLoad according to whether status bar and navigation bar are there.
I have set a UITabBarController as the root view controller in the AppDelegate.
I have added a loading view upon the window, while the app downloads some data. I have hidden the status bar while the loading screen is visible. As soon as the loading is done, I fade the loading view and shows the status bar again.
My problem is that when I show the status bar the navigation bar was not drawn to have the right height, because the status bar was hidden when it was drawn. If I change to another tab it gets the right height.
I have tried with [navigationController.view setNeedsLayout], but that seems to get the position of the view of the ViewController right, but the content of the navigation bar does not resize. I have also tried with [navigationController.navigationBar setNeedsLayout], but that does help at all.
So I basically want to get the navigation drawer get the right height for the status bar and content when the loading view fades. How can I do this?
Have you try to reset the navigation and status bar as like below?
-(void)resetNavigationBar
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController setNavigationBarHidden:NO];
}
I would unhide the status bar in the viewWillDisappear: method on the loading view.
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
I see people are having problems with hiding the status bar in iOS 7.1, but I have the opposite problem. I'm unable to unhide once it has been hidden. :)
This piece of the code works perfectly fine on both iOS 7 and 7.1. It will hide the status bar and show the image picker.
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
imagePickerController.showsCameraControls = YES;
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
}
self.imagePickerController = imagePickerController;
[self presentViewController:imagePickerController animated:YES completion:nil];
However, the part that is supposed to bring the status bar back doesn't work any more in iOS 7.1:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
[self dismissViewControllerAnimated:YES completion:NULL];
This code will dismiss the image picker, but the status bar will remain hidden.
Any ideas how to solve this issue?
OK, I figured something out. The problem doesn't lie in setStatusBarHidden:NO itself, but in its combination with the image picker.
It seems that in iOS 7.1 the image picker (the camera one) will hide the status bar on its own (that wasn't the case in iOS 7.0). So, if I also hide it manually, the status bar is hidden twice and that seems to break something.
To conclude: hiding the status bar manually before showing the camera image picker is pointless in iOS 7.1 because the image picker itself will hide it.
Hiding and showing the status bar without using the image picker works just fine.
In my app, I do not intend to show the status bar. So, my app covers the whole screen view. I could manage doing it inserting the
- (BOOL) prefersStatusBarHidden{
return YES;
}
method in my main viewController and also adding to my app delegate
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
This all works well when I open the app in the portrait mode. However, when opened in the landscape mode, while the status bar gets hidden, I see a black band of background image on top of my view. Indeed my view is vertically offset by the height of status bar height (see picture below).
This does not happen if I open the app first in portrait mode and then rotate. So, I am doing something wrong in the initialization of the view frame I thought, which I do by the usual
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
[self.view setFrame:screenRect];
Any suggestions on this would be really appreciated.
Thanks in advance,
Nikhil
I seem to have fixed the issue (at least for now). I did not fix in the info-plist the options
I hate this. To do one single setting one has to add so many things, that too in different places: one in the appDelegate, other in the main view controller and yet another completely outside the code :(.
I have a view controller that displays full screen, and from the view controller another modal VC can be presented, the modal VC requires status bar, but after dismissing the modal VC controller, the base VC has the space for status bar on top, and even I set:
[[UIApplication sharedApplication] setStatusBarHidden:YES]
the status bar is hidden but the space is still there, and I checked the frame of the view of the base VC, it starts from 0, I don't think I should make its y-coordinate starts from -20, but what else can I do?
Thanks
Try this out:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
self.view.frame = [[UIScreen mainScreen] applicationFrame];
From the docs on applicationFrame:
This property contains the screen bounds minus the area occupied by
the status bar, if it is visible. Using this property is the
recommended way to retrieve your application’s initial window size.
The rectangle is specified in points.
For a more robust solution, change your frame in response to a status bar frame change. Your application delegate subclass can implement:
-application:willChangeStatusBarFrame:
-application:didChangeStatusBarFrame:
Or, you can register for these notifications using NSNotificationCenter:
UIApplicationWillChangeStatusBarFrameNotification
UIApplicationDidChangeStatusBarFrameNotification
I've tried your method, but it did not work for me, I solved it in this way, when the modal VC dismisses, in the viewDidAppear of base VC I need to:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
self.wantsFullScreenLayout = YES;
[self.view layoutSubviews];
I know this is not a good solution, but it is the only thing I could think of at the moment, thanks anyway for your help.