Container View getting pushed down as if it had a UINavigationBar?
What you are missing here is that a translucent navigation bar sits on top of your viewcontroller's view, while a non-translucent navigation bar pushes down your view controller's view (effectively resizing it).
So what is happening here is that with a translucent navigation bar, that white space is actually hidden underneath the bar, while when the bar is not translucent it's "pushed down".
There are a number of ways to go about it, and it mainly depends on whether you're using auto layout or not.
setNavigationBar translucent pushes view down
The property you want to set is extendedLayoutIncludesOpaqueBars
, if this property is set to YES then your view will layout the same as if the navigation bar were translucent.
You mentioned that you're not using storyboards, but for others who do this can be set in the Attributes Inspector for the view controller under the 'Extend Edges' section by ticking the checkbox titled 'Under Opaque Bars'.
How can I keep the container view getting effected by the UINavigationBar
So, it seems the problem wasn't specific to Container Views. I tried the same thing with prototype cells in a regular UITableView
inside my UIViewController
that has the UINavigationController
, and the same thing happened. It appears this is an auto-layout problem or something. So as far as a solution goes, I don't have a real one other than, just make the Container or UITableView
as large as the UIViewController
in Storyboards.
Add children view controller in a controller that pushed in a navigation controller
The problem cause is by default UIViewController
's view
has FlexibleWidth
&FlexibleHeight
bController
and cController
's view
has extra gap 64 pixel (navBar(44) + status bar(20)). Now when you resize it has those 'FlexibleWidth&
FlexibleHeight` to play with.
Solution could be making autoresizingMask
to .None
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.greenColor()
bController = b()
cController = c()
bController.view.autoresizingMask = .None
cController.view.autoresizingMask = .None
displayContentController(bController, toFrame: CGRect(x: 0, y: 0, width: 100, height: 100))
displayContentController(cController, toFrame: CGRect(x: 0, y: 100, width: 100, height: 100))
}
UINavigationController NavigationBar extra space at the top of the view
You need to set Adjust Scroll View Insets
to false. To fix it try:
InterfaceBuild: https://stackoverflow.com/a/26567240/846780
Code: self.automaticallyAdjustsScrollViewInsets = NO;
Animating down the position of a UINavigationBar from a UINavigationController - iOS
Your research is excellent already, and your conclusions are pretty much spot on. A UINavigationController's navigation bar's isn't yours to move or resize, animated or not. It isn't your navigation bar, period. If you really want a view controller that acts this way, write your own parent view controller (as you very reasonably suggest).
In a container view, a navigation controller's navigation bar not resizing to include status bar
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.
Related Topics
Symbolicate Crash in iOS8 with Xcode 6 .1
iPad - Parsing an Extremely Huge JSON - File (Between 50 and 100 Mb)
(iOS + Storekit) How to Detect When I'm in the Sandbox
Swift How to Modify Exif Info in Images Taken from Mobile Camera
Full Resolution Screenshots for iPhone 6 and 6+
Xcode: How to Change Layout of Views Between Landscape and Portrait Mode
Launching Phone/Email/Map Links in Wkwebview
Creating a Tutorial for My iOS App with Page Control
Core Data: Delete All Objects of an Entity Type, Ie Clear a Table
Uinavigationcontroller Interactivepopgesturerecognizer Working Abnormal in iOS7
Get Tapped Word from Uitextview in Swift
Is There Any Limitation to Distribution of Apps in iOS Enterprise Program
How to Detect a Dual Core CPU on iOS
Obj-C Afnetworking 2.0 Post Request Does Not Work