2

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

iamVishal16
  • 1,780
  • 18
  • 40
LondonGuy
  • 10,778
  • 11
  • 79
  • 151

5 Answers5

2

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 .. :)

Rashad
  • 11,057
  • 4
  • 45
  • 73
  • How am I accessing my viewWillAppear method? This signUpViewController is created in code. How do I access it from within the tappedJoinButton method? This where I am stuck. – LondonGuy Apr 03 '14 at 06:06
  • 1
    @LondonGuy >> check if there is any property for hiding status bar or you can make a subclass of signUpViewController (without status bar). Then you can access the property of PFSignUpViewController. In that class you can declare these or prefersStatusBarHidden method. – Rashad Apr 03 '14 at 06:37
  • I just created a new class which was a subclass of PFSignUpViewController and then created an instance of that. In the new class I set preferred status hidden method to return yes and it worked fine. – LondonGuy Apr 03 '14 at 07:30
  • @londonGuy >> Nice to hear that. :) – Rashad Apr 03 '14 at 07:37
  • This API is deprecated – Daniel Galasko Dec 22 '16 at 10:18
1

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;
}
Rashad
  • 11,057
  • 4
  • 45
  • 73
0

you lust like ....

if ([UIApplication sharedApplication].statusBarHidden != hideStatusBar)
{

    [[UIApplication sharedApplication] setStatusBarHidden:hideStatusBar withAnimation:UIStatusBarAnimationSlide];
}
0

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

        }
Parvendra Singh
  • 965
  • 7
  • 19
0

Add this "View controller-based status bar" appearance in the plist and set NO

  [[UIApplication sharedApplication] setStatusBarHidden:YES];  
Rose
  • 437
  • 2
  • 9