With the status bar initially visible, I add a subview and hide the status bar:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[myController.view addSubview:anotherController.view];
In this view there is a button to toggle the status bar visibility, but when I set statusBarHidden to NO again, the view controller's view doesn't auto resize to take into account the status bar, and as a result the view is pushed down and cut off by 20px. I've set all the appropriate resizing masks to the view and also tried auto-layout, but neither seem to work. I'd like my view to resize automatically when showing/hiding status bar without manually setting its frame.
Update
Instead of adding it the root view controller's view, I've pushed it onto the stack of my navigation controller, and hidden the status bar and navigation bar. I then give the user the option to toggle only the status bar. However the problem still remains and the view is pushed and cut off by 20px when the status bar reappears.
But when I rotate the device, everything is in its place - only if I rotate the device after the status bar has been hidden.
How is myController added to the window? Assuming that myController is the rootViewController of your window, than this controller should resize correctly when displaying / hiding the statusBar. The view of anotherController should be added in another way, than just adding its view. But still, if you give that view the correct resizing flags, it should also resize. But it would be better, if you push that controller on a navigationController, or if you set it as the new rootViewController.
Related
I have created a storyboard layout which contains UIViewControllers within UINavigationControllers which all connect back to a UITabBarController. There is a login page which is not connected to anything (just a UIViewController) which segues into the UITabBarController when the app detects user authentication. You can see what this looks like in the following image:
When I set the translucent property of the Navigation Bar to "false" or "No", the view y origin gets pushed down to the bottom of the Navigation Bar (which is the behavior that I am looking for). However, when I set the translucent property of the Tab Bar to "false" or "No", the Tab Bar DOES become opaque, but the view is not resized to fit between the top and bottom bars. I have unchecked the Extend Edges property for both Under Top Bars and Under Bottom Bars for all UIViewControllers, UINavigationControllers, and the UITabBarController.
When I add subviews programmatically (no auto-layout), the UIViewController's view is still the height of the entire screen, and is only pushed down from the top bar, but not pushed up from the bottom bar. While creating this question, this is the result I got on the simulator (subviews are not even starting below the Navigation Bar):
The layout that I'm trying to achieve is to have the view fit between the Navigation Bar and the Tab Bar so that both bars are opaque and no content goes underneath them. Any ideas or suggestions?
EDIT:
After eliminating individual Navigation Controllers and adding a single one before the TabBar Controller, I'm getting weird behavior including navigation items disappearing and one of my subviews still goes under bottom bar.
EDIT 2:
After doing some research, It seems that having navigation controllers inside each tab is a normal view hierarchy. Unfortunately, I still have not figured out how to limit a view controller's view to be between a navigation bar and a tab bar. Any suggestions?
I have created an application which needs to have a bar above the navigation bar and other views. To accomplish this, I am using a view controller with a view for the top bar, and then a container view for everything else. Sometimes, the top bar needs to be hidden. I'm using autolayout to hide the top bar (set its height to 0), and the container view expands to fill the screen (container top equal to the top bar bottom). The container view contains a navigation controller because I need a navigation bar below the top bar sometimes. When I start the app, this all works fine as shown below:
As you can see, the navigation bar stays the desired height, which is expanded to include the status bar
However, when the top bar is tapped, I use a segue to present (not push) a view controller from my root view controller (not the container), and then I look at the same screen with the navigation bar, the navigation bar is no longer extended and it overlaps the status bar as seen below:
Why would presenting a view controller break this? And then how could I rectify this or prevent it?
One possible solution I could do is present a view controller from within the container view, that works, I would just have to set the current view controller in the container to a delegate of the root controller, so that when the top bar is tapped, it tells the view controller in the container to present the new view controller. This would not be my first option however, especially if there are other scenarios which cause this problem.
Thanks for any help!
You need to turn automaticallyAdjustsScrollViewInsets off for all of your child view controllers and manage the insets (or setup so they aren't required) yourself. By default automaticallyAdjustsScrollViewInsets is on for all view controllers (which is what you want for 'full screen' presented VCs.
At the moment you see controllers almost randomly updating to reorganise themselves for the scroll insets as the VC hierarchy changes.
I'd probably turn automaticallyAdjustsScrollViewInsets off for all VCs (apart from root) and change your header view so that it's full height or status bar height (which should be the length of the topLayoutGuide of the root VC). When collapsed to status bar height your header view could also change colour to match that of the current top VC.
I am using a search bar plus controller for a UITableview in my MasterController. When the view shows up, the navigationbar in the MasterController is black until the view fully loads (not sure why?). In order to fix this I set the self.navigationController.navigationBar.translucent = false; This fixed the issue I was having with the navigation bar being black initially, but now it looks like when I click a cell in the uitableview of the MasterController, the content in the DetailView that loads shifts down approximately the size of the search bar, but it's just blank space above the content that has been shifted... When I remove the translucent property in the MasterController the content in the DetailView is fine and not shifted...
SO my question is, what is shifting this content down and how can I stop the content from being shifted AND having an opaque navigation bar...
In iOS 7, by default your view controller's view extends under a translucent navigation bar when contained in a UINavigationController but not on an opaque one. You could set the extendedLayoutIncludesOpaqueBars property of the view controller if you want it to extend under opaque nav bars too.
When you say your scroll view is shifted on your detail view controller it's probably because its y origin is not set to zero to offset for your view extending under a translucent nav bar, but because your nav bar is now opaque and your view is not extending under it the space is now visible.
One thing more view controllers will actually automatically add insets on scroll views they contain so that their contents are not obscured when the view controllers view extends under navigation bars. It is set by the automaticallyAdjustsScrollViewInsets property which is by default is set to YES.
I've read a few questions here and searched around a bit but nothing seems to solve my problem. I have a side navigation controller of which I am sliding the status bar (using a technique outlined here: Moving status bar in iOS 7).
In any event, when I hide the status bar to begin the slide (as soon as I tell the view to hide the status bar and add a fake one), the entire view moves up behind my faux status bar. Is there any way to move the view down so that the faux status bar appears directly above the view?
may be some autolayout issueAs there is no status bar , the view frame went to frame.origin.y=0. Try setting the frame to origin.y=20 before you hide the status bar.
If you are adding fake status bar as subview to mainView. set frame of fake status bar view to (origin.y=-20)
I have stumbled across a weird problem when implementing a view container which is connected with child view controllers.
The hierarchy is the following:
I have a UISplitViewController and in the MasterViewController I added a view container which is connected to a UIViewController which is embedded in a UINavigationController.
The outcome is the following:
The ChildViewController leaves a white space at the top which seems to be exactly as high as the status bar. How can I avoid that the status bar frame is shown in the child view controller?
I tried to set wantsFullScreenLayout for the ChildViewController and for its UINavigationController but it doesn't change anything.
I also tried to set the y offsets of the views to -20.0 points but that ends up in another problem.
Only when I set status bar hidden for the application it is not shown for the ChildViewController but that in turn also hides the status bar at the top of the UISplitViewController.
Would be glad for some hints.
Basically it looks like the top gap is the status bar. The statusbar at the moment is 'light' colored which is why it's not showing on top of the white background. Try changing the background color of the view controller to black or use one of the appearance callbacks to change the status bar to a darker color.