I am trying to subclass the UINavigationController to add a custom subview underneath its UINavigationBar. The problem is when I set my custom UINavigationController as the rootViewController of my window, the UINavigationBar position changes, so I want to update the position of my custom view accordingly. My question is where should I put my code to update my custom view.
var navController = TabbedNavigationController(rootViewController: firstView)
// navController.navigationBar.frame.origin.y = 0
self.window?.rootViewController = navController
self.window?.makeKeyAndVisible()
// navController.navigationBar.frame.origin.y = 20.0
What you are trying to do is respond to the positioning of subviews of the navigation controller's view. Positioning of subviews is called layout, and takes place in
layoutSubviews. Thus, you could try implementingviewDidLayoutSubviews, which is called immediately afterlayoutSubviews. Note that it can be called many times but you may want to add your subview only once, so be careful to add appropriate guards.