Broken UISearchBar animation embedded in NavigationItem

前端 未结 7 665
孤城傲影
孤城傲影 2020-12-01 03:01

I am experiencing a problem with the new way of adding search bar to the navigation item.

As you can see in the picture below, there are two UIViewControllers one af

7条回答
  •  旧巷少年郎
    2020-12-01 03:56

    In the VC1:

    override func viewDidLoad() {
       if #available(iOS 11.0, *) {
            navigationItem.hidesSearchBarWhenScrolling = false
            navigationItem.searchController = searchController
        }
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if #available(iOS 11.0, *) {
            navigationItem.hidesSearchBarWhenScrolling = true
        }
    }
    

    In the VC2, use the same code.

    This will solve your problem more clearly, than set serchController to nil

提交回复
热议问题