简体   繁体   中英

Navigation bar flashes when cancelling back swipe

I have a pretty simple setup:

The root view controller has the navigation bar hidden, and the secondary view controller ( Settings ) has the navigation bar shown with a large title. To achieve the hiding and showing of the navigation bar, I do this:

In the root view controller:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    navigationController?.setNavigationBarHidden(false, animated: animated)
}

That's it. And this works perfectly except for this special case: When I pan right as if I am dismissing the secondary view controller but then pan back left to cancel, the navigation bar flashes while the secondary view controller animates back as it should. Here is what this looks like in slo-mo:

screengrab

This same exact thing happens if I move the navigation bar hiding into the secondary view controller's viewWillAppear(_:) .

How can I stop the flashing and make this work right?

Even though I do not have a solution, exactly, I have figured out what caused the problem:

If you set the status bar to be hidden in addition to the navigation bar, the navigation bar will jump like in the video in the OP.

The solution for my personal case was basically to hide the status bar only in viewDidAppear . The downside is that means that the status bar alpha does not animate when you drag.

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