iOS: StatusBar appearance error - ios

I have first ViewController with Portrait orientation and second ViewController with landscape orientation. The first ViewController have status bar, the second have not.
Then I present second ViewController from the first ViewController, it presenting with out status bar. Then I dismiss it I go back to first ViewController and have my status bar, but the position of the View is incorrect.
View position like screen have not status bar. How can I update it?

first, try this:
In your landscape VC declare the following:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:true];
// you can also try to hide the status bar with animation:
[[UIApplication sharedApplication] setStatusBarHidden:true withAnimation:UIStatusBarAnimationSlide];
}
In your portraint VC declare the following:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:false];
// you can also try to show the status bar with animation:
[[UIApplication sharedApplication] setStatusBarHidden:false withAnimation:UIStatusBarAnimationSlide];
}

Related

ios hide status bar with animated

I want to disable navigation bar animation when page change.,
root viewController
- (BOOL)prefersStatusBarHidden{
return YES;
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];,
}
pushed viewController
- (BOOL)prefersStatusBarHidden{
return NO;
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];,
}
If both pages statusBarHidden is equal to NO or YES this method work but when i disable one of them a problem occurs. I could not upload image because of my reputation very low please check link for image.
https://www.facebook.com/photo.php?fbid=154038544933435&set=a.154038594933430.1073741827.100009818700445&type=1&theater
you should used this it work for me on tab gesture
NSTimer *timer;
if([UIApplication sharedApplication].statusBarHidden == YES)
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
timer= [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(hideStatusbar) userInfo:nil repeats:NO];
}
calling methods
-(void)hideStatusbar
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
Implementing prefersStatusBarHidden should do the trick. No need to override viewWillAppear:animated, because iOS animates automatically from one status bar state to the next.
Be sure to set "View controller-based status bar appearance" in your Info.plist to YES.
As far as the navigation bar is concerned. If you use storyboards and use Segueues you can transition from one Navigation Controller to the another. If navigation Controller A has a visible Navigation Bar and Navigation Controller B has a hidden Navigation Bar, iOS will automatically animate the Navigation Bar away for you.

Status bar text color changing

So I have an app which mainly consists of web views. Everyhting is working fine, I have my status bar and navigation bars configured as I like.
The only issue is, when I go to a website that has a "Choose File" option, it opens the Saved Images to select a image (no issue here), then when I tap on the saved images table cell, the status bar text goes from white to black and I am unable to revert back.
I have tried calling UIStatusBarStyleLightContent in viewDidAppear, viewDidDisappear, etc which solves it reverting, but only on that single view it changes.
Any ideas on how to keep it UIStatusBarStyleLightContent all the time? I should note I have [UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; declared in the App Delegate, and UIViewControllerBasedStatusBarAppearance set to NO.
Thanks.
UPDATE with screenshots:
UPDATE 7/14
I managed to get it somewhat working, but in turn it broke the default video player status bar text. Plus it just won't hide to begin with.
I used:
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
-(void) viewDidDisappear:(BOOL)animated {
[self.webView stopLoading];
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
FINAL UPDATE??
Not pretty, but i managed to somewhat get the effect all together between the video player and image uploader.
-(void) viewDidDisappear:(BOOL)animated {
[self.webView stopLoading];
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationNone];
}
Set "View controller-based status bar appearanceā€ to NO in your info.list file;
Add this code
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
to -application:didFinishLaunchingWithOptions: of the AppDelegate.m.
I hope your problem will be solved

How do I hide the status bar of a pushed view controller in objective c?

I have a signup form that pops up when a button is tapped.
My aim is to hide the status bar when this modal is popped up.
Here is my code:
- (IBAction)tappedJoinButton:(id)sender {
if (![PFUser currentUser]) {
PFSignUpViewController *signUpViewController = [[PFSignUpViewController alloc] init];
[signUpViewController setDelegate:self]; // Set ourselves as the delegate
// Present the sign up view controller
[self presentViewController:signUpViewController animated:YES completion:NULL];
}
}
I have set View controller-based status bar appearance to yes in my plist file. Now I'd like to choose where I hide the status bar. In this situation I'd like to hide it in the signUpViewController that pops up.
I haven't seen any answers on here showing how to hide it in a pushed view controller.
How do I achieve this?
Kind regards
If you want to hide status bar for only one ViewController the do this:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[super viewWillDisappear:animated];
}
For your case it will be in PFSignUpViewController.
Hope this helps .. :)
Try this code
in viewDidload of PFSignUpViewController
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
paste this function in controller
- (BOOL)prefersStatusBarHidden {
return YES;
}
you lust like ....
if ([UIApplication sharedApplication].statusBarHidden != hideStatusBar)
{
[[UIApplication sharedApplication] setStatusBarHidden:hideStatusBar withAnimation:UIStatusBarAnimationSlide];
}
Write this in your viewWillAppear...
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Or try This method ....
-(void)navigationController:(UINavigationController *)
navigationController willShowViewController:(UIViewController *)
viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Add this "View controller-based status bar" appearance in the plist and set NO
[[UIApplication sharedApplication] setStatusBarHidden:YES];

Status bar appears again after showing MPMediaPickerController modal

I hid status bar in my app by setting [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; and by this code:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
By when I show the MPMediaPickerController modal with [self presentViewController:mpMediaPlayerController animated:YES completion:^{}];, the status bar is being show again.
How can I hide it?
Subclass the MPMediaPickerController and add:
- (BOOL)prefersStatusBarHidden {
return YES;
}
After getting back from MPMediaPlayerController again hide status bar in ViewWillAppear method
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Hope it will work.

How to hide status bar automatically after load view

guys,
I want to hide the status bar in the code. After loaded view, the status bar will show and it will automatically hide after a while. How to do that?
You want UIApplication's setStatusBarHidden:withAnimation:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
See the docs.
Haven't tested it and there might be a better way but if you put the following in your load view function:
[self performSelector:#selector(hideNavBar) withObject:nil afterDelay:0.0];
and then have this function
-(void) hideNavBar {
if (self.navigationController.navigationBar.hidden == NO)
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
}
You might have to hide the navigation bar in a view animation block. but some combination should work
Check out
link
You could simply do it in you AppDelegate, when applicationDidBecommeActive ("After loaded view").
Set hide status after 400ms, with UIView animation block and calculate your root view controller's navigation bar
// AppDelegate.m
#import "AppDelegate.h"
#import "SomeViewController.h"
#interface AppDelegate ()
#property (nonatomic, strong) SomeViewController *someViewController;
#end
#implementation AppDelegate
- (void)applicationDidBecomeActive:(UIApplication *)application
{
UINavigationBar *navBar = self.someViewController.navigationController.navigationBar;
if (![[UIApplication sharedApplication] isStatusBarHidden]) {
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationSlide];
[UIView animateWithDuration:0.4
animations:^{
navBar.frame = CGRectMake(navBar.frame.origin.x, 0, navBar.frame.size.width, navBar.frame.size.height);
} completion:nil];
}
}
#end
that's it, "After loaded view (didBecomeActive), the status bar will show and it will automatically hide after a while (400ms)"
You have to select your project and select Hide during application launch inside the header General, section Deployment Info like this:
And inside the info.plist set the View controller-based status bar to NO:

Resources