简体   繁体   中英

Hide and show navigation bar for specific view without laggy animation

Is there a way to show navigation view on one view and not show it on another at the same time?

The problem: I have two view controllers - table and description view (called on cell click).

Table got a navigation bar, while description view - don't have it.

Table view:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    self.navigationController?.isNavigationBarHidden = false
}

Description view controller:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationController?.isNavigationBarHidden = true
}

Everything works fine, but when i swipe for half screen back to table (keeping finger on screen, watching both views) - i don't see navigation bar (which works as expected with that code), and when i release finger - whole table view jumps, because nav bar is shown.

Is there a way to keep not seeing nav bar in description view and see it all the time in table view?

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    self.navigationController?.setNavigationBarHidden(false, animated: true)
}



override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationController?.setNavigationBarHidden(true, animated: true)
}

You can hide the navigation bar while doing the segue (earlier). If you're doing it programmatically:

yourVCToBePushed.navigationController?.isNavigationBarHidden = true

If you're doing it in the storyboard, do similarly inside prepareForSegue:

let yourVCToBePushed = segue.destination as! YourVCToBePushed (type)
   yourVCToBePushed.navigationController?.isNavigationBarHidden = true

You can also create your own "navigationView" inside tableView header, and add buttons there.

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