Setting navigationController?.navigationBar.isTranslucent = false in iOS 15 makes back button hit target too small and not work

Viewed 248

Super weird bug where my Navigation Controller back button wasn't working unless I tapped really right on it. On device it barely worked, on simulator I could click around and find the veeeery small hit target.

Here's what my nav bar settings look like in viewWillAppear

navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.tintColor = .white
navigationController?.navigationBar.barTintColor = .black
navigationController?.navigationBar.barStyle = .black
1 Answers

Turns out the problem line was this line inside my viewWillAppear:

navigationController?.navigationBar.isTranslucent = false // This line causes the hit target to be super small!

When I removed that line the hit target seemed to work fine (but of course my appearance was way off).

I found this question which had a similar problem and solved my issue by re-working my entire appearanace to look like so:

let navAppearance = UINavigationBarAppearance()
navAppearance.configureWithOpaqueBackground()
navAppearance.backgroundColor = .black // previously my barTintColor
navAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
navigationController?.navigationBar.standardAppearance = navAppearance
navigationController?.navigationBar.scrollEdgeAppearance = navAppearance // yes, you need this

// Need this one legacy setting to change the buttons to be white
navigationController?.navigationBar.tintColor = .white
Related