iOS 11 prefersLargeTitles not updating until scroll

前端 未结 24 2969
轻奢々
轻奢々 2021-01-31 07:25

I implemented a basic UIViewController with a UITableView that\'s wrapped in a UINavigationController. I set prefersLargeTitles to true:

override fu         


        
24条回答
  •  感动是毒
    2021-01-31 08:07

    Similar issue for me with a UITableViewController added to a UIViewController. In my instance, these view controllers are themselves embedded in a UITabBarController and only the first tab displayed correctly used a large title. Other tabs required a manual scroll before the large title was displayed.

    The only thing I could get to work was adjusting the contentInset as per @pau-senabre's answer, except I the top inset wasn't helpful for me. Instead, I set the left inset and then reset it on the next runloop.

    private var isFirstAppearance = true
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    
        if isFirstAppearance {
            applyLargeTitlesFix()
        }
    }
    
    private func applyLargeTitlesFix() {
        let originalInset = tableViewController.tableView.contentInset
        tableViewController.tableView.contentInset = UIEdgeInsets(top: 0, left: 1, bottom: 0, right: 0)
        DispatchQueue.main.async { [weak self] in
            self?.tableViewController.tableView.contentInset = originalInset
        }
        isFirstAppearance = false
    }
    

提交回复
热议问题