I'm using an ad client in my project. The Ad client makes the application's status bar hidden. Can I do something to force the application to show status bar?
some code in objective C because i know only objective C
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// Hide the status bar
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)])
{
// iOS 7
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
}
else
{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
}
- (BOOL)prefersStatusBarHidden
{
return NO;
}
Related
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
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];
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;
}
i want to hide status bar hidden in both ios 6.0 and ios 7.0.
please can you explain any common method which work in both ios version for ios.
please provide solution :-
thanks.
Update In Plist add these property.
Status bar is initially hidden = YES
View controller-based status bar appearance = NO
Programatically
- (void)viewDidLoad {
[super viewDidLoad];
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)])
{
[self prefersStatusBarHidden];
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
}
else
{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
} }
// add this too
- (BOOL)prefersStatusBarHidden {
return YES; }
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: