ios hide status bar with animated - ios

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.

Related

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

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

Hiding navigation bar/status bar/prompt

For the life of me, I cannot figure out how to get rid of the white bar at the top of my app.
http://cl.ly/image/3Z2I1x0H3H17
I am currently using a navigation controller as the root view. I've also tried just having a UIViewController as the root view.
In the first UIViewController I have tried:
- (void)viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:YES animated:NO];
}
This does nothing.
I have also tried:
- (BOOL)prefersStatusBarHidden {
return YES;
}
Which hides the status icons (battery, cell connection indicator).
But really, I just want all that white space gone.
Try:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Or set Status Bar to 'None' in the XIB.
In viewDidLoad add this code:
//checks if device is running iOS 7 (or newer) or iOS 6 (or older)
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
} else {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
Then add this method:
- (BOOL)prefersStatusBarHidden {
return YES;
}

Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar

I am trying to implement a tap gesture on my web view to hide/show the navigation bar, tab bar, and status bar. I have the hiding/showing of the navigation bar working fine and I can hide the status bar but not get it to show back up. The tab bar items get hidden but the bar is still there. Can anyone help with this?
- (void)toggleBars:(UITapGestureRecognizer *)gesture
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
BOOL statusBarHidden = YES;
BOOL barsHidden = self.navigationController.navigationBar.hidden;
[self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
BOOL tabBarHidden = self.tabBarController.tabBar.hidden;
[self.tabBarController.tabBar setHidden:!tabBarHidden];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIBarButtonItem *systemAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(showMenu)];
self.navigationItem.rightBarButtonItem = systemAction;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(toggleBars:)];
[webView addGestureRecognizer:singleTap];
singleTap.delegate = self;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
EDIT: It looks like the tab bar is hiding but my webview just isn't filling the empty space. How can I have it fill the space when the tab bar is hidden?
First of all, your status bar never unhides because you never tell it to. As written your code merely tells the status bar to hide every time it is executed.
[[UIApplication sharedApplication] setStatusBarHidden:![[UIApplication sharedApplication] isStatusBarHidden] withAnimation:UIStatusBarAnimationSlide];
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBar.hidden animated:YES];
Additionally, I'm not sure about the details of why your tab bar isn't hiding properly, but I did find the following category which claims to be able to hide the tab bar with option animation.
https://github.com/idevsoftware/Cocoa-Touch-Additions/tree/master/UITabBarController_setHidden
I got the status bar to hide/show by adding this to my toggleBars method, but I still haven't figured out why the tab bar items hide but not the tab bar itself.
if (([UIApplication sharedApplication].statusBarHidden = YES))
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}
else
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}

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