How to hide status bar automatically after load view - ios

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:

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.

iOS: StatusBar appearance error

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];
}

SKStoreProductViewController shows the status bar in iOS7

In iOS7, when a SKStoreProductViewController is presented, it shows the status bar, making it difficult to hit the [Cancel] button.
Can it be disabled?
In my app, UIViewControllerBasedStatusBarAppearance ("View controller-based status bar appearance") is set to YES.
Putting the following code anywhere in the project:
#interface SKStoreProductViewController (StatusBarFixing)
#end
#implementation SKStoreProductViewController (StatusBarFixing)
-(BOOL) prefersStatusBarHidden { return YES; }
#end
... seems to do the trick, even if it is a bit sketchy. However, it would only work if UIViewControllerBasedStatusBarAppearance is set to YES
It seems to me that the status bar is not meant to be shown here. In my opinion, it's best to just hide the status bar and everything will look like it's supposed to.
-(void)showAppInAppstore {
SKStoreProductViewController *spvc = [[SKStoreProductViewController alloc] init];
spvc.delegate = self;
// ... start activity indicator here if you wish
__weak typeof(self) weakSelf = self;
[spvc loadProductWithParameters:#{SKStoreProductParameterITunesItemIdentifier : #(APP_STOREID)}
completionBlock:^(BOOL result, NSError *error) {
// there is no way to stop this task so...
// make sure that user hasn't navigated away from "rate" screen
if(weakSelf != nil && weakSelf.isViewLoaded && weakSelf.view.window != nil) {
// ... stop activity indicator here
if(result == NO || error != nil) {
// handle error if needed
} else {
// Hide status bar
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
// Present store controller
UIViewController *controller = [UIApplication sharedApplication].keyWindow.rootViewController;
[controller presentViewController:spvc animated:YES completion:nil];
}
}
}
];
}
Now make sure that the status bar becomes visible once user is done
-(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}
You can subclass SKStoreProductViewController and control status bar appearance from that point. That's simple and elegant.
SKStoreProductViewControllerWithoutStatusBar.h
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
#interface SKStoreProductViewControllerWithoutStatusBar : SKStoreProductViewController
#end
SKStoreProductViewControllerWithoutStatusBar.m
import "SKStoreProductViewControllerWithoutStatusBar.h"
#interface SKStoreProductViewControllerWithoutStatusBar ()
#property (nonatomic) BOOL wasStatusBarHidden;
#end
#implementation SKStoreProductViewControllerWithoutStatusBar
// Works if UIViewControllerBasedStatusBarAppearance == NO
- (void)viewWillAppear:(BOOL)animated {
self.wasStatusBarHidden = [[UIApplication sharedApplication] isStatusBarHidden];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[[UIApplication sharedApplication] setStatusBarHidden:self.wasStatusBarHidden withAnimation:UIStatusBarAnimationSlide];
[super viewWillDisappear:animated];
}
// Works if UIViewControllerBasedStatusBarAppearance == YES
- (BOOL)prefersStatusBarHidden {
return YES;
}
#end

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];

setStatusBarHidden not working

In my UIViewController, I have:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[self.view sizeToFit];
}
Yet the view looks like this:
I'm sure this code runs. I load the view from a xib. I haven't done anything else to the status bar like change its style. What could be wrong?
Even when I set `application.statusBarHidden = YES" in my app delegate, I see:
In your app's plist, if you have "View controller-based status bar appearance" set to YES, put this code in the view controller in which you hide the status bar:
- (BOOL)prefersStatusBarHidden {
return YES;
}
Else if "View controller-based status bar appearance" is set to NO, call the following whenever you want to hide the status bar.
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
if you want to hide Status Bar in your app , Follow this steps :
Step 1 :
Step 2:
Step 3:
Add to your appDelegate didFinishLaunchingWithOptions function
application.statusBarHidden = YES;
so :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
application.statusBarHidden = YES;
}
That's because iOS 7 has changed the way it deals with the status bar.
Setting UIViewControllerBasedStatusBarAppearance to NO on your app Info.plist should work.
You can show/hide your app status bar using the following code (Works on IOS 7 - IOS 8 and IOS 9):
in your project .h file add this boolean:
BOOL isShowStatus;
And in .m file add this:
//To show the status bar:
-(void)showTheStatusBar
{
isShowStatus = YES;
[self setNeedsStatusBarAppearanceUpdate];
}
//And to hide the status bar:
-(void)hideTheStatusBar
{
isShowStatus = NO;
[self setNeedsStatusBarAppearanceUpdate];
}
- (BOOL)prefersStatusBarHidden {
return !isShowStatus;
}
Simply call it from anywhere, didload for example:
- (void)viewDidLoad
{
[super viewDidLoad];
//To show the status bar:
[self showTheStatusBar];
//Or to hide it:
[self hideTheStatusBar];
}
For me it works fine:
- (BOOL)prefersStatusBarHidden {
return YES;
}
ALWAYS in the root view. If you are doing that in a subview will not work because status bar visibility will be taken from parent view.
Try adding this after you hide the status bar:
[self.view setFrame:[self.view bounds]];
In your appdelegate.m in didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
application.statusBarHidden = YES;
}
When I run your code:

Resources