About statusBar within application - ios

Sorry, I don't know how to expound this issue! Looking at the below image
The front view not show statusBar, but the back view appear within app. Like this, how to achieve? Thanks.

If I understand your question correctly, you want to hide the StatusBar during the Application Launch.
To achieve this you simply have to set a checkbox in your project settings. Click on your Target and click on the checkbox "Hide during Application Launch".
If you really want to hide the StatusBar for a single view you can use in viewWillAppearthe following piece of code:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
And in viewWillDisappearsimply set the value to NO.

You can hide the status bar with:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
You could put that code within the front view controller's viewDidLoad: method:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
//...
}
And you can show it again with:
[[UIApplication sharedApplication] setStatusBarHidden:NO];

Related

How to hide status bar for specific viewcontroller in ios 9, using objective-C

I want to hide the status bar for specific view controllers, not for all.
then I tried this,
[[UIApplication sharedApplication] setStatusBarHidden:YES]; in the `.AppDelegate.m` inside the `didfinishlaunchwithoption` but it didn't work. and also it is deprecated.
then I tried in my viewcontroller
- (BOOL) prefersStatusBarHidden{
return YES;
}
this also didn't work. anyone can help me with this.thnak you
I don't want to use any deprecated methods here
Go to info.plist and add two attributes if not present. set "Status bar is initially hidden" to "YES" and set "UIViewControllerBasedStatusBarAppearance" to "YES". This will hide status bar for your app.
-(BOOL)prefersStatusBarHidden
{
return YES;
}
and call this method where you want,For example from viewDidLoad
[self prefersStatusBarHidden];
I want to hide the status bar for specific view controllers, not for all.
Only the top-level view controller gets to say whether the status bar is hidden. Your prefersStatusBarHidden is not consulted because your view controller is not the top-level view controller — it has some kind of parent view controller which is in charge of the status bar.
Try the code below in your view controller.
Try the following method without deprication warnings:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
}
- (void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
[super viewWillDisappear:animated];
}
Update for iOS 9
Add the following code in your viewController for hiding status bar.
- (BOOL) prefersStatusBarHidden {
return YES;
}
Try below code in your view controller.
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[super viewWillDisappear:animated];
}
Add below code to your view controller..
- (BOOL)prefersStatusBarHidden {
return NO;
}
If you change the return value for this method, call the setNeedsStatusBarAppearanceUpdate method.
For childViewController, To specify that a child view controller should control preferred status bar hidden/unhidden state, implement the childViewControllerForStatusBarHidden method.

Can't hide status bar on launch

I'm building an iOS 9 app with horizontal pages navigation and need to show the status bar on some pages, and hide it on others. I want to use the fade in/out animation so I have to set
View controller-based status bar appearance = NO
and update the status bar like this:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
This procedure works perfectly when navigating between pages, but I can't get rid of the status bar on launch.
I have tried setting: Status bar is initially hidden = YES
Adding this to the NavigationControllers viewDidLoad:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.statusBarHidden = YES;
[self setNeedsStatusBarAppearanceUpdate];
Adding this to AppDelegates didFinishLaunchingWithOptions:
application.statusBarHidden = YES;
Adding this to the ViewController of the initial page:
- (BOOL)prefersStatusBarHidden {
return YES;
}
Checking the "Hide status bar" option in General->Deployment Info
And setting "Status Bar" to "None" in the linked storyboard element
But the status bar is still showing up on launch. How can I get rid of the status bar on launch without changing the value of View controller-based status bar appearance ?
Just tick the hide status bar in project setting as below.
Project setting - For hiding the status bar at launch of app.
Add below in viewController for which you need to hide.
- (BOOL)prefersStatusBarHidden {
return YES;
}
/------ UPDATE -----/
With tick of hide status bar
Without tick of hide status bar
/------ Animate Status Bar -----/
In plist.
View controller-based status bar appearance = NO
Then in viewWillAppear method.
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
changing plist file :
set Status bar is initially hidden = YES
add row: View controller-based status bar appearance = NO
Goto Targets->General->Deployment Info: and under that select Hide Status Bar option.
Turns out what I was doing was correct, but there was an errant [[UIApplication sharedApplication] setStatusBarHidden:NO]; buried in inherited code. I grepped it, but overlooked that line...
(use git grep StatusBar to find lines of code in a git repo that mutate the status bar)
Also, the only code needed is:
View controller-based status bar appearance = NO (in plist)
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
anywhere the status bar needs updating (usually in viewWillAppear)
In order to achieve what you are looking for you need set in the app.plistfile:
Status bar is initially hidden to YES
View controller-based status bar appearance to NO
Then in every view controller to show it
[[UIApplication sharedApplication] setStatusBarHidden:NO];
or to hide it:
[[UIApplication sharedApplication] setStatusBarHidden:YES];

Hide status bar in iphone/ipad apps

I'm working on an application for iPhone iPad.
My test iPhone (v4) is on iOS 6.
My test iPad is on iOS 7.
I'd like to remove both statuses bar from the whole application.
Here's what I've tried :
In info.plist, I've set Status bar is initially hidden to YES and View controller based status bar to NO
This didn't work.
So I've set View controller based status bar to YES and in my main view controller I've added :
- (BOOL)prefersStatusBarHidden{
return YES;
}
Though this function never gets called.
In this same controller I've added this to loadview:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
This worked for the iPhone, but the bar still shows up on iPad.
Thanks for your help.
EDIT :
I also have checked "Hide during application launch" in project settings.
EDIT :
Here are two screenshots of my project settings.
http://imgur.com/a/VXZTk
As you can see I've tried the answers of the question you voted this as a duplicate to.
If I'm not doing it wrong, thanks for voting to re-open this question.
You need to have two things to have the status bar hidden throughout whole app in all iOS versions
In info.plist View controller based status bar set to NO . (For iOS 7)
In your applicationDidFinishLaunching add [[UIApplication sharedApplication] setStatusBarHidden:YES]; or simply [app setStatusBarHidden:YES]
Now you can optionally set Status bar is initially hidden to YES also to hide status bar when app launches.
Also if you dont want status bar to be hidden throughout the app.
remove [[UIApplication sharedApplication] setStatusBarHidden:YES]
and override prefersStatusBarHidden in your ViewControllers and return YES or NO
- (BOOL)prefersStatusBarHidden{
return YES;
}
If you set Status bar is initially hidden to YES, it will work fine.
Anyways Have you tried below methods?
-(void)viewDidLoad
{
[super viewDidLoad];
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)])
{
[self prefersStatusBarHidden];
[self setNeedsStatusBarAppearanceUpdate];
}
}
-(BOOL)prefersStatusBarHidden
{
return YES;
}
- (UIViewController *)childViewControllerForStatusBarHidden
{
return nil;
}
Thanks!
Just needed to set deployment infos to universal.
Click xCode project/your target/General/Deployement Info, then check the "hide during application launch"

Resizing every view to fit again after toggling setStatusBarHidden:YES to setStatusBarHidden:NO

I have a UIView that I want to add to the keyWindow so that it covers everything (including the StatusBar). When I add the view I remove the statusBar using the following piece of code:
[[UIApplication sharedApplication].keyWindow addSubview:aView];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
aView.frame = [[UIApplication sharedApplication].keyWindow bounds];
Everything looks as expected. If I then remove the view and add the statusbar again, everything is fine. However, things go wrong when I rotate my device and then remove the view. The UI is now partially covered by the statusBar (in this case a nav bar). Rotating the device immediately resizes everything so that the UI looks normal again.
How can I ensure the UI (any UI!) is aware of the StatusBar unhiding again so that it adjusts automatically as soon as the UIView is removed from the keyWindow.?
The solution should work, regardless of the type of UI in the App. I happen to use a tab bar and a navigation controller in this particular example, but that doesn't always have to be the case.
I have just solved this problem.
In my situation, it is caused by the order you call the method.And sometimes maybe the animation also have something to do with this.
for example,in my situation:
//call present view controller after call setStatusBarHidden
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[modalPresentedViewController presentModalViewController:self animated:YES];
//call setStatusBarHidden before call the dismiss method.
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[modalPresentedViewController presentModalViewController:self animated:YES];
I hope this will help.

IOS 4.3 hide status bar permanently

I'm trying to hide the status bar in iOS 4.3 now that setStatusBarHidden:animated: is deprecated:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; //deprecated
The only option that exists in the plist file is: Status bar is initially hidden. Which only hides the status bar at the start of the app.
Cheers
Try this:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
From Apple Class Reference:
setStatusBarHidden:withAnimation:
Hides or shows the status bar,
optionally animating the transition.
- (void)setStatusBarHidden:(BOOL)hidden
withAnimation:(UIStatusBarAnimation)animation
Parameters
hidden
YES to hide the status bar, NO to show the status bar.
animation
A constant that indicates whether there should be an animation and, if
one is requested, whether it should
fade the status bar in or out or
whether it should slide the status bar
in or out.
But how about [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
See the UIApplication reference.
The new method is:
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation
Works the same except the animation type is an enum now to support various animation types.
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
seStatusBarHidden seems to be deprecated and not working anymore.
Use prefersStatusBarHidden on your view controller instead
- (BOOL)prefersStatusBarHidden
{
return YES;
}

Resources