iOS 13 UIBarButtonItem not clickable and overlapping UINavigationBars when using UISearchController

前端 未结 4 1296
醉酒成梦
醉酒成梦 2020-11-29 01:13

I got a navigation bar containing some UIBarButtonItem buttons and a UISearchBar hooked up like this

var searchController: UISearch         


        
相关标签:
4条回答
  • 2020-11-29 01:53

    I'm now using this workaround as I want most of my users have the navigation bar visible while search is active (for several app-ux-specific reasons).

    var isIosVersionWithNavigationBarBug: Bool {
        if #available(iOS 13.2, *) {
            return false
        }
        if #available(iOS 13.0, *) {
            return true
        }        
        return false
    }
    

    In my search controller I use it like this

    mySearchController.hidesNavigationBarDuringPresentation = isIosVersionWithNavigationBarBug
    

    So if iOS 13.2 is being released and the user updates to it, the workaround is not being applied anymore.

    0 讨论(0)
  • 2020-11-29 02:02

    The view debugger reveals what's going on with this bug. The contents of the navigation bar are being copied. Here's what the navigation bar looks like before you show the search:

    And here's what it looks like afterwards:

    The two replicant views and the extra UILabel are the problem. I don't know what they're doing there and I can't find a way to remove them.

    EDIT By the way, I think some of Apple's apps display the same bug. It's easier to see if you have large titles, because then you can see the large title and the extra label at the same time:

    0 讨论(0)
  • 2020-11-29 02:07

    This appears to be fixed in iOS 13.2 beta, I tested the example project above using Xcode 11.2 beta (11B41).

    0 讨论(0)
  • 2020-11-29 02:16

    Not proud of it but I got it working for now with this hack.

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        let viewsToRemove = self.navigationController?.navigationBar.subviews.flatMap({ (view) in
            view.subviews.filter { type(of: $0) == UILabel.self }
        })
        viewsToRemove?.forEach { $0.removeFromSuperview() }
    }
    
    0 讨论(0)
提交回复
热议问题