Search code examples
iosswiftuinavigationbarios11uinavigationitem

Prevent UINavigationItem's TitleView from blinking


I'm using UINavigationItems titleView property to set view in center of UINavigationBar of my ViewController. The problem is, when I push another ViewController with same titleView, it blinks.

Animation showing Blinking of titleView

Here is how I set titleView inside my ViewControllers

let view = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
view.backgroundColor = .red
self.navigationItem.titleView = view

What can I do to prevent this?


Solution

  • I ended up using custom view and adding it as subView to UINavigationBar. I'm also setting UINavigationItems titleView to blank view to prevent LargeTitle from appearing in place of my view.