0

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.

Community
  • 1
  • 1
George
  • 3,384
  • 5
  • 40
  • 64

1 Answers1

0

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

Community
  • 1
  • 1
yurish
  • 1,515
  • 1
  • 15
  • 16
  • Thank you @yurish. Before I did the above actions, I tried to use `[[self navigationController] setNavigationBarHidden:YES animated:YES];`, it would give a 320-point wide and 64-point high blank area at the bottom of the window, so that my content view of the navigation controller's view (which is a web view) didn't respond to click event (in iOS 7 only) even if I extend the height for that content view with additional 64 points. – George Dec 06 '13 at 08:05
  • 1
    Something is wrong with layout settings. Do you have height constrain on the root view? Anyway its better to use setNavigationBarHidden to hide the bar and find where is the problem with layout. – yurish Dec 06 '13 at 08:12
  • To @yurish what kind of height constraint is recommended? – George Dec 06 '13 at 08:15
  • You should not have it on the root view. – yurish Dec 06 '13 at 08:16
  • Thank you! @yurish, a solution (though not recommended by Apple's principle) is using [[self navigationController] setNavigationBarHidden:YES animated:YES]; with a topLayoutGuide added, the code can be found here: http://stackoverflow.com/questions/20418548/where-to-add-toplayoutguide-constraint-code – George Dec 06 '13 at 10:02