The navigation bar is black during custom Segue unwinding

I created a custom UIStoryboardSegue , but when it unwinds, it seems that my UINavigationBar will turn black, and then go back to the correct color. See below GIF.

enter image description here

My custom segue just makes the new ViewController go down and down.

Here is the UIStoryboardSegue code:

 import UIKit class SlideDownSegue: UIStoryboardSegue { var duration: Double = 0.5 override func perform() { let screenHeight = UIScreen.main.bounds.size.height let toVC = self.destination let fromVC = self.source toVC.view.transform = CGAffineTransform(translationX: 0, y: -screenHeight) UIApplication.shared.keyWindow?.insertSubview(toVC.view, aboveSubview: fromVC.view) UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: { toVC.view.transform = CGAffineTransform.identity }, completion: { success in fromVC.present(toVC, animated: false, completion: nil) }) } } class UnwindSlideDownSegue: UIStoryboardSegue { override func perform() { let screenHeight = UIScreen.main.bounds.size.height let toVC = self.destination let fromVC = self.source.parent! fromVC.view.superview?.insertSubview(toVC.view, at: 0) UIView.animate(withDuration: 0.5, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: { fromVC.view.transform = CGAffineTransform(translationX: 0, y: -screenHeight - 100) }, completion: { success in fromVC.dismiss(animated: false, completion: nil) }) } } 

If I allow the default unwinding when it just leaves, going to the bottom of the screen, but retaining its custom to display the new view, the UINavigationBar maintains its correct color, it is only when I used my code that during the animation the UINavigationBar turns black.

Any clues would be greatly appreciated.

--- EDIT ---

I played around with it a bit if I go to AppDelegate and change UINavigationBar.appearance().isTranslucent = false to true, instead I get a white background, but then it just appears that the navigation bar appears suddenly. I am wondering if this is for some reason unloaded and then loaded back when the View Controller is active.

--- EDIT 2 ---

I can fix this with a hack. In the AppDelegate inside the func application(... didFinishLaunchingWithOptions ...) I added to self.window?.backgroundColor = UIColor.{your color} , but all that does is that the black part now appears in my color, by for some reason, the navigation bar still disappears during segue.

+7
ios11 swift4 uistoryboardsegue uinavigationbar xcode9
source share
2 answers

This is a great opportunity to use snapshotView(afterScreenUpdates:) . The way UIKit performs many of its share transitions (even in the UINavigationController ) is a terrific way to make custom transitions, especially if you want to apply effects. Take a snapshot of the destination (which will have an intact navigation bar), paste it directly below the source code, perform an animation, release the source so that the target is ready, and finally delete the snapshot that you won’t even notice because it accurately reflects the place destination.

+2
source share

If you need a simple trick, try setting the background color of the window in AppDelegate didFinishLaunchingWithOptions to your navigation bar color, it works for me :) how is this window?.backgroundColor = myColor

+1
source share

All Articles