Is window the super view of [[window rootViewController] view]

1k views Asked by At

Question

Is application's window (of the type UIWindow *, a property in app delegate) the super view of [[window rootViewController] view]?

My code in the app delegate method application:didFinishLaunchingWithOptions: is [self window setRootViewController:[self myNavigationController]] (self refers to the app delegate). Note that I didn't write [self window addSubview:[[self myNavigationController] view]];.

I programmatically create all views (no storyboard, no interface builder), using non-ARC, Xcode 5, iOS 7.

Context of the question

The reason that I need to know this question is that I want to add a topLayoutGuide constraint to the [[window rootViewController] view]'s super view, where the window's rootViewController is a navigation controller.

Though I'm not sure about whether it is better to create a customized container view controller to contain the navigation controller, so that we can add the topLayoutGuide constraint to the container view controller's view (now clearly it's the superview of the view of navigation controller).

The reason that I need to add that topLayoutGuide constraint is there seems a bug of my code when I show/hide navigation bar by changing the frame of navigation controller's view. When I set the frame of navigation controller's view (also the [[window rootViewController] view]) by shifting frame's origin's y coordinate 64 points (the height of status bar's 20 points plus the navigation bar's 44 points) upper, the navigation controller's content view has unexpectedly shift another 20 points underneath the navigation bar in iOS 7 only. This unexpected behavior reminds me of a problem solved by adding topLayoutGuide.

1

There are 1 answers

5
yurish On BEST ANSWER

When you assign a root controller to a window the root view of the controller becomes subview of the window. So yes the window is a superview of window.rootViewController.view.

Not sure though why you are hiding the navigation bar by changing the frame of the navigation contoller. The navigation controller has built in facility for this: Navigation bar show/hide