can't set to "UIBarPositionTopAttached" on navigationBar - ios

I made UIViewController which have navigationController as parent (connected in storyboard),
and I want to apply picture of navigationBar for statusBar background.
but it seems that statusBar can't be state like "Translucent",
I tried to set
- (void)viewWillAppear:(BOOL)animated {
[self.navigationController.navigationBar setBackgroundImage:[UIImage
imageNamed:#"barTop.png"] forBarPosition:UIBarPositionTopAttached
barMetrics:UIBarMetricsDefault];
[self setNeedsStatusBarAppearanceUpdate];
....
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
in UIViewController.
But backgrounds of navigation and status Bar have been separated.
I try both to make plist file as "View controller-based status bar appearance" YES and NO. but still I can't configure statusBar from viewController.
I couldn't find same problem in this bulletin board .
does anyone knows solution??or how to debug?
thank you for reading.
(9/3 added: I want to make backgrounds together for navigationBar and statusBar.
And under the simple condition like that there are one navigationController and one ViewController, both bars can make their backgrounds together (default).
Now I met the something wrong when I make tabBarController indicate to multiple navigationController by storyboard.)

According to Apple for Status bar, status bar is Transparent.(I think* always, not sure). Here is the link. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Bars.html

Although I found the solution this a few month ago,it took a time to align the point.
checking my viewController structure causing problem , It found Black of the statusBar is self.window.backgroundColor.
so this mean status bar and navigationController was originally succeeded to be transparent, my viewController is aligned (20, 0). this was root of this problem.
and I found that this problem derived from applying contentInsets setting.
this setting affects to even view.subviews[0] too.
this happen when under some condition
•uiViewController’s view displayed via UInavigationController
•edgesForExtendedLayout is active
•view’s first element is kind of UIScrollView or these subclass
(from japanese bulletin board)
to solute this , I made originally navigationController on the storyBoard to separate from these inset setting then I explicitly set its origin to (0,0)
and I set automaticallyAdjustsScrollViewInsets = NO on my viewController.
after that, finally I could set viewController’s origin to (0,0), and I made navigationBar’s back being statusBar’s back.
below link contains so much useful information.
iOS 7 status bar back to iOS 6 default style in iPhone app?

Related

Can see Status Bar space but not information in iOS Swift

I add Navigation Controller(2nd View) and add one UIViewController(3rd View) as root view controller.
And then I connect segue to Navigation Controller(2nd View) from anther UIViewController(1st View).
So I can see navigation Bar with Status bar space when the view is presented.
But the information like Carriers, batteries, time information are not shown in Status Bar.
(I changed navigation Color to pink for showing you the problem.
The blue part is title view for navigation bar.)
So I tried 2 solutions.
First, I thought StatusBar Color problem. But it was not.
UIApplication.shared.statusBarStyle = .default
Second, I tried following code for showing. It was not also.
override var prefersStatusBarHidden: Bool {
return false
}
and
UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none)
I need to solve this not-showing problem with status Bar.
I can see status Bar space but not information.
There are lots of ways to toggle the color and visibility of the status bar in iOS.
Similar question with possible correct answers for you:
How to change Status Bar text color in iOS 7
In short, if you want to toggle it between every screens, follow these steps:
In your info.plist, add this new key:
View controller-based status bar appearance and value should be NO.
In your viewWillAppear, toggle the status bar with the code you have posted:
UIApplication.shared.statusBarStyle = .lightContent - white
or
UIApplication.shared.statusBarStyle = .default - black
Edit:
Initial ViewController --> Present Modally --> NavigationController + ViewController.
This is how you set up your screens, right?. If so,
You can setup the status bar in your NavigationController properties in your Interface Builder.
And toggle the visibility and/or color of your status bar in side the viewWillAppear of your 3rd ViewController.
I suggest you check out Debug View Hierarchy.
Based on my experiences in previous projects, if I can't come up with code-based solutions on UI-related problems the simplest debugging technique that I can do is check the view hierarchy during run time.
See if the Navigation Controller View blocks the Main View which can possibly hide the status bar and if yes, work your way on solving it.
I hope it helps.

UINavigationBar moves under status bar when using swipe back gesture from status bar hidden viewController

The problem is simple, the Profile viewController has a NavigationBar just under the status bar. I push another viewController on top of the current one. This new viewController hides the status bar.
When I go back USING A SWIPE BACK GESTURE to the Profile viewController, the navigationBar has moved up by the size of the status bar height.
The related question is UINavigationBar moving under status bar when another viewController hides status bar
Any ideas?
Actually,
in that case too, using the following also works.
[[UIApplication sharedApplication] setStatusBarHidden:NO];
Calling this in viewWillDisappear of the second view controller solves the issue.
The main View controller contains a main view and I add a tableView in within the view (the blue-ish color on the screenshot is the header of the tableview).
Somehow, this composition doesn't layout really well... I have no idea why.
Somebody wrote that to avoid this kind of layout issues, using a scrollView as a container makes the trick but I can't add tableViews to a scrollView...
If anybody has an explanation about why this layout problem happens, I'd be happy about it.

setStatusBarHidden deprecated, but only thing that works

I've tried all the solutions I can find including those in: setStatusBarHidden is deprecated in iOS 9.0 but none of them work with my application.
It is a simple, single view application. There is a Navigation bar with a single button on it which the status bar should show on top of.
In my .plist:
Status bar is initially hidden: NO
Status bar style: UIStatusBarStyleLightContent
View Controller based status bar appearance: NO
Changing any of these doesn't seem to make any difference at all. I have the status bar style "Hide during application launch" option checked as I don't want it to appear on the splash screen.
I have:
- (BOOL)prefersStatusBarHidden
{
return NO;
}
-(UIStatusBarStyle)preferredStatusBarStyle
{
NSLog(#"style");
return UIStatusBarStyleLightContent;
}
and setNeedsStatusBarAppearanceUpdate which are definitely all called when the view loads in my ViewController.
The view is established in a .storyboard, but many of the fields are manipulated in the ViewController.m as well. The value assigned to the status bar in the simulated metrics doesn't seem to have any effect either.
I need my status bar to be hidden during the launch screen and visible on the viewController. Please help me find a solution that doesn't use the deprecated setStatusbarHidden!
EDIT:
I still haven't solved this, and I surely can't be the only one with this problem! It happens in both apps that I have written.
I've just been trying to solve the same problem, I don't know why the setStatusBarHidden and setStatusBarStyle have been deprecated as the new methods are not at all intuitive.
To hide the status bar on launch I have these settings in my plist:
View controller-based status bar appearance: YES
Status bar is initially hidden: YES
Then to show the status bar after launch I have in my view controller:
- (BOOL)prefersStatusBarHidden {
return NO;
}
-(UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
This still didn't work until I found this answer https://stackoverflow.com/a/19365160/488611. So in viewDidLoad I also set the navigation bar style:
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
Which makes absolutely no sense, but works.
you can use
application.statusBarHidden=YES;
in AppDelegate.m
didFinishLaunchingWithOptions
In my mind, you should change the value of UIViewControllerBasedStatusBarAppearance.
Set the value file .plist of project a is
UIViewControllerBasedStatusBarAppearance = NO
and check in file AppDelegate and set the code
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Hope my solution can be solved your problem.
OK, I totally misunderstood your question. Here's the correct answer.
Add the below value to you 'info.plist'.
Status bar is initially hidden : YES
View Controller based status bar appearance : YES
On UIViewControllers which you want to show status bar
- (BOOL)prefersStatusBarHidden {
return NO;
}
That's all.
I am not an expert on this, but I played with these settings for some time and came to the following conclusions.
General/Deployment Info:
Status Bar Style: Default (black), Light
Hide status bar (checkbox)
Both change the status bar on the launch screen only.
Note that if you take a screen shot to create this image and the screen shot included a status bar, it will appear that the device is setting the status bar even if you have checked the Hide status bar checkbox! I was tricked by this for a while before I finally thought to look at the launch image itself, and there was a status bar in the photo, so setting Hide never seemed to work even though it really was working. I removed the status bar from the images themselves using Photoshop, and the launch status bars functioned as expected after that.
Info/Custom iOS Target Properties (these change the values in the PLIST, so you could change them in either place):
Status Bar Is Initially Hidden: Yes/No
Status Bar Style: Gray (default), Transparent Black, Opaque Black
View Controller based status bar appearance : Yes/No
If you set Status Bar Is Initially Hidden to No, then you will have the status bar on your View Controller like you wanted. If you want to hide the status bar on your View Controller, you have to set Status Bar Is Initially Hidden to Yes AND set View Controller based status bar appearance to No.
Attributes Inspector for the View Controller/Simulated Metrics
Status Bar: None, Inferred, Default, Light, Black (deprecated)
This seems to have no effect on anything except the appearance of the view controllers in the StoryBoard but NOT in the simulator.
Summary: To answer your question, under General Deployment Info, check the checkbox that says Hide Status Bar. This will hide the status bar on the launch screen. Make certain that your image for the launch screen does NOT have a picture of a status bar in it. None of the settings in the StoryBoard or in the Target seems to turn off the view controller's status bar, so it seems that it will stay on like you wanted. However, I did not test any of the programmatic settings; I think that you should not do any of those, and it will work the way you want.

UINavigationController transparent for UITableView underneath

I have a UINavigationController handling then navigation in my app. I would like the navigation bar to show the contents of the UITableView as I scroll up.
I can't seem to get it to be transparent. I have it set to translucent
self.navigationController.navigationBar.translucent = YES;
But still nothing. I'd like to add color, but I'll worry about that later. I've tried creating a subclass of UINavigationController and specify
self.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.translucent = NO;
But again, no luck. This is what my interface builder looks like...
And this is what it looks like when I scroll the text up under the nav bar. Any suggestions?
Alright, I figured out a (seemingly simple) solution.
If you're using a UINavigationController to add a UINavigationBar to each of your views, this will work for making a transparent navigation bar.
Select the Navigation bar in your UINavigationController
Then, in the inspector bar (on the right), select "Clear Color". Tada! I'm a bit embarrassed I didn't try this sooner. Hopefully this will save someone else lots of time.
Try using a UITableViewController embedded in a UINavigationController, instead of a UIViewController. It'll adjust the insets for the iOS7 live blur automatically, so that the list content will show up under the Toolbar/NavigationBar on scroll.
I can't really make it out from your screenshot, but you can disable 'Hide Toolbar' in the parent NavigationController. You then don't have to add it separatly.

how to present a view controller on iOS7 without the status bar overlapping

I'm seeing when I migrated my app to iOS 7, the nav bar is appearing under the status bar when presenting a view controller. I think a lot of people have run into this same issue. Here's a screenshot of what I'm seeing:
Requirements:
The new view must appear "modally", i.e. I need presentViewController.
Display some sort of nav bar or toolbar, with the status bar taking on the background color of the nav bar ala iOS 7 style.
It must work on iOS 6.
I'm using a xib to handle layout, with autolayout enabled.
Options:
A. Shift your view's frame down by a bit.
Ugh, are we back to the pre-iOS 5 days and mucking with frames? Also it's generally not a good idea mixing with autolayout.
B. Add a little gap up top below your nav bar.
One disadvantage of options A and B is the status bar won't blend into your nav:
C. Programatically add constraints.
The main disadvantage is you'll have to muck with constraints and calculating the nav and status bar heights. Yuck.
D. Stretch the navigation bar / toolbar's height to include the area of the status bar.
Looks good on iOS 7, but breaks on iOS 6. You'll need to programatically update the height of the nav bar, and also make sure the rest of your view updates appropriately. Messy.
E. Mess with iOS6/7 deltas in IB.
Multiple disadvantages: You'll be hardcoding the ios6/7 deltas. Also doesn't work with autolayout.
F. Use a nested UINavigationController.
This is the workaround I selected. See answer below.
The easiest workaround I've found is to wrap the view controller you want to present inside a navigation controller, and then present that navigation controller.
MyViewController *vc = [MyViewController new];
UINavigationController *nav = [[UINavigationController alloc]
initWithRootViewController:vc];
[self presentViewController:nav animated:YES completion:NULL];
Advantages:
No mucking with frames needed.
Same code works on iOS 6 an iOS 7.
Less ugly than the other workarounds.
Disadvantages:
You'll probably want to leave your XIB empty of navigation bars or toolbars, and programatically add UIBarButtonItems to the navigation bar. Fortunately this is pretty easy.
You need to add a Vertical Constraint from your top most view to Top Layout Guide as described in the following article by Apple.
https://developer.apple.com/library/ios/qa/qa1797/_index.html
Next code worked for me. Just put it to the controller which is presenting the new controller.
#pragma mark hidden status bar
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
open you xib file and select the viewcontroller. in the inspector tab select the attributes and select in TopBar "Opaque Navigation Bar".
this solved the problem for me.

Resources