LargeTitles UIScrollView does not support multiple observers implementing _scrollViewWillEndDraggingWithVelocity:targetContentOffset

前端 未结 5 2447
执笔经年
执笔经年 2021-02-20 09:15

I have implemented large titles in my app with the following code:

if #available(iOS 11.0, *) {
            navigationController?.navigationBar.prefersLargeTitle         


        
5条回答
  •  臣服心动
    2021-02-20 09:54

    The problem happened when the tableview was still scrolling when I went to another view. I fixed the problem by setting a bool in the scrollViewDidScroll that disables any scrolling when the segue is started.

        func scrollViewDidScroll(_ scrollView: UIScrollView) {
            if viewIsVisible {
                if scrollView.contentOffset.y <= 0 {
                    if #available(iOS 11.0, *) {
                        self.navigationItem.largeTitleDisplayMode = .always
                    } else {
                        // Fallback on earlier versions
                    }
                } else {
                    if #available(iOS 11.0, *) {
                        self.navigationItem.largeTitleDisplayMode = .never
                    } else {
                        // Fallback on earlier versions
                    }
                }
                self.navigationController?.navigationBar.setNeedsLayout()
                self.view.setNeedsLayout()
                UIView.animate(withDuration: 0.01, animations: {
                    self.navigationController?.navigationBar.layoutIfNeeded()
                    self.view.layoutIfNeeded()
                })
            }
        }
    
        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            self.viewIsVisible = false
    }
    

提交回复
热议问题