简体   繁体   中英

Adding Subview to UINavigationController Subclass

I have subclass the UINavigationController and add a custom subview underneath the UINavigationBar. I update the position of my subview in the viewDidLayoutSubviews() method. However, with this method when I add a viewController to the navigationController, the viewController's view will be hidden behind my custom subview. How should I add the subview so does it does not cover up my viewController's view?

override func viewDidLoad() {
    self.view.addSubview(tabView)
}

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    tabView.frame = CGRect(x: 0, y: self.navigationBar.frame.origin.y + self.navigationBar.frame.height, width: self.view.frame.size.width, height: 40.0)
    navigationViewHeight = tabView.frame.origin.y + tabView.frame.size.height

}

You should consider subclassing UINavigationBar instead of UINavigationController. Here's an example of adding a subview to a custom nav bar https://gist.github.com/timothyarmes/7080170

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM