Status bar won't disappear - hidden

I'm creating an application and I want the status bar hidden. When I test the app, the status bar is hidden whilst the splash screen is shown, but once the app is fully loaded, the status bar reappears.
I'm using Xcode 5 and iOS 7, and have tried disabling the status bar programatically
([[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationFade];),
in the info.plist file, and using the attributes inspector on the .xib file. Nothing appears to work.
Any ideas?

Try adding the following method to your app's root view controller:
- (BOOL)prefersStatusBarHidden
{
return YES;
}

You should add this value to plist: "View controller-based status bar appearance" and set it to "NO".
This will enable you to set the status bar to hidden mode. This sets it to a global unlike other provided answers.
UPDATE: If you want that the status bar would be hidden on splash screen don't forget to mark "Hide during application launch" on target status bar options.
Also, you can add "Status bar is initially hidden" to "YES" on the plist if you don't want to do it with code inside the app.

The code you posted works for iOS 6.1 and below. For iOS 7, Apple has made new methods available to directly control the status bar for each view. Turning off this option in your Info.plist will enable you to hide the status bar, at least for the current Developer Preview (4).
For reference, please take a look at the iOS 7 transition guide that's available on Apple's developer portal.

well I try hide the status bar in all my app and in the "app"-info.plist and I add two rows in the dictionary "Information Property List" I add "View controller-based status bar appearance" set NO and in "Status bar is initially hidden"set YES and for me works n_n'

However, if you use UIImagePicker, the status bar appears again.
In that case, you should hide the status bar as below,
- (void)imagePickerController:(UIImagePickerController *)aPicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// for iOS7
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}

After some long searching, I finally found a very simple solution which also takes care of the UIImagePickerController problem.
As mentioned in the other answers, set your status bar hidden in your AppDelegate didFinishLaunching, and set the "View controller-based status bar appearance" to NO.
Then, in your AppDelegate:
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
et voila - your Status Bar will remain hidden even when the UIImagePickerController is foremost.
This is better than 'rehiding' it every time you present a UIImagePickerController as it remains hidden throughout the app.

To hide the status bar on a particular UIViewController, simply add this:
-(BOOL)prefersStatusBarHidden
{
return YES;
}
Hope this helps !

You can hide from the project summary. there is a checkbox hide during launch.
See the snapshot

I found this solution for me. It works like a charm.
Write this code on your viewcontroller which you wanted to use UIImagePickerController on.
- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
- (void)viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}

In addition to the answer from alones above, make sure to implement the imagePickerControllerDidCancel method and add the same code there too.

I was having issues with UIImagePicker as well. Similar to Alones answer, my solution was the following. I added this line or code:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
to this function:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
I haven't tested this with iOS 6 or older but it works great in iOS 7.

Swift Solution
just add this to your view controllers:
override func prefersStatusBarHidden() -> Bool {
return true
}

I am using Xcode 6, this solution works on iOS 7 and 8 for me:
First, Set the "View controller-based status bar appearance" to NO in plist file.
Second, in AppDelegate, add this:
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}

My problem was that I used view controller containment. Only the top most view controller, which is embedded into a navigation controller for example, can hide or show the status bar.

Related

How to hide status bar in ios13 in cocos-2dx

I was using
<key>UIStatusBarHidden</key>
<true/>
in info.plist file to hide status bar for ios. Also in my RootViewController.mm is
- (BOOL)prefersStatusBarHidden
{
return YES;
}
to fix hiding status bar on ios7.
Everything worked fine untill I tried this code on ios13. At ios13 status bar does not hide anymore. Does anybody know how to hide status bar for ios13?
I also tried to add
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
in info.plist, but nothing seemed to work.
You shoudle View controller-based status bar appearance set is true
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
[UIApplication sharedApplication].statusBarHidden = YES;
or
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
- (BOOL)prefersStatusBarHidden{
return YES;
}
Finally, I found the reason for that.
my project was missing launchscreen storyboard.
Adding launchscreen storyboard Seeing black bars at the top and bottom of the iPhone X Simulator and hiding safe area https://forums.developer.apple.com/thread/89037 and setting launch screen file in general settings allowed to hide status bar.

How to allow a button that creates a new object in SwiftUI from not making an object on reload?

So I'm making a button for a "New Note" in Swift UI similar to the Apple Notes app.
Right now my "New Button" is a "Navigation Link" like so:
NavigationLink(
destination: EditorView(makeNewNote())
) {
Text("New")
}
Unfortunately—this triggers my app to create a new note every time the view loaded. :(
:/
I've been looking for a way to initate a segue on button push but I'm not finding success on this yet.
When I tried a modal—I found myself having the same problem
Button("New") {
self.isNew = true
}.sheet(isPresented: $isNew, content: {
EditorView(makeNewNote())
})
I'm wondering what the best way to approach this would be.
Having no success :(
Edit:
I referred to this and the documentation but I haven’t found a way to segue via a button push which would be ideal. (The function dosent get triggered in the closure :)
https://www.hackingwithswift.com/quick-start/swiftui/how-to-push-a-new-view-onto-a-
Also...if you were curious what makeNewButton() does—it basically inserts a new Core Data object into my app’s managed context.
I'm not entirely sure, but it kinda sounds like to me your problem lies in your model. Because each time your View loads it calls the makeNewButton() function right?
Maybe you can fix the problem by displaying the "new note" view and having an extra "Save" button that only makes changes to your model once it's triggered.
Alternatively, you could use context.rollback() to discard changes. Also, check out this Project. It's Beta 4 but works just the same and imo is a good example how to use CoreData with SwiftUI. :)

Touch Up Inside event not working after rotation of tab bar

I have a button in one of view controller of tab bar controller. All set up in storyboard. I registered action method like this
- (IBAction)buttonPressed:(id)sender {
NSLog(#"Button pressed");
}
The thing is that once I make left and top constraints (to force it stay in the right upper corner) touch up inside event stops working after I change rotation. So just open app in portrait mode - method is working. Change to landscape and I cannot tap button suddenly.
I've recreated problem in this easy example project.
Many thanks.
Just put the following code in you TabBarViewController class.
- (void)viewDidLayoutSubviews
{
// fix for iOS7 bug in UITabBarController
self.selectedViewController.view.superview.frame = self.view.bounds;
}
Recently I noticed same bug in my application. First I tried Slavco Petkovski method. But this caused me another bug with rotating and getting right bounds and frame, so I kept searching.
I found another solution for this problem, mainly setting autoresizing mask of view controller's view in xib. But since arrows in inspector in my Xcode (version 5.0.1) are inactive and you can't set them, you have to open xib file in text editor find autoresizingMask property for main view and change it like this:
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
EDIT:
Alternatively you can do this in your view controller's code - same result as in changes in xcode:
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

Hide the tabBar in Rubymotion

I am building an iOS app in Rubymotion. I want to create a custom tabBar so I need
to use a real tabBar but hide it. How can I hide the tabBar in Rubymotion?
To hide the tab bar you can use hidesBottomBarWhenPushed.
The Objective C is:
MyController *myController = [[MyController alloc]init];
myController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myController animated:YES];
[myController release];
Therefore the RubyMotion Code is
#my_controller = MyController.alloc.init
#my_controller.hidesBottomBarWhenPushed = true
self.navigationController.pushViewController(#my_controller, animated:true)
I hope this helps. If you'd like to see more references to tab bars please check:
https://github.com/IconoclastLabs/rubymotion_cookbook/tree/master/ch_2/12_tabbars
Or if you'd like to see basics of navigation controller please check
https://github.com/IconoclastLabs/rubymotion_cookbook/tree/master/ch_2/11_navbarbuttons
I hope this helps!

Orientation delegate method is not getting called while rotating the tabs under more section

In my project the tabs which are not under more section are properly responding to orientation but the tabs present under the more section are not responding.
For example if I am having two tabs names tab1 and tab2 under more section and if I am putting break point at the "shouldAutorotateToInterfaceOrientation" method of each tab.After that when if I am selecting tab1 from more section and tries to rotate it but the "shouldAutorotateToInterfaceOrientation" of the tab2 gets called.The delagate method of the tab which I am selecting is not getting called.I am working on XCode Ver 4.3.2.
Can someone please help me in solving this problem..
Thanks in advance,
Prajnaranjan Das
Please write followings code of all the root view controller of tab bar controller.
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return yes;
}
i face the same prblm as you facing now...
i was Return YES (shouldAutorotateToInterfaceOrientation Function) to all the view Controller classes inside tababarcontroller and my problem solved..
try to do this...might be you also get success
I used this method for orientation. Its working properly.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
}
There are several other methods which may help you in orientation such as:
• willRotateToInterfaceOrientation
• didRotateFromInterfaceOrientation
• willAnimateFirstHalfOfRotationToInterfaceOrientation
• willAnimateSecondHalfOfRotationFromInterfaceOrientation