iOS 11 prefersLargeTitles not updating until scroll

前端 未结 24 2334
轻奢々
轻奢々 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条回答
  • I had the same issue only on one tableview ...

    I had to set :

    self.tableView.contentInsetAdjustmentBehavior = .never
    

    so that my tableview stop scrolling when uiviewcontroller was loaded.

    It's the tableview automatic scrolling that makes the large title being hidden

    Hope this helps

    0 讨论(0)
  • 2021-01-31 08:16

    Programmatically:

    1. In AppDelegate.swift:
            window = UIWindow(frame: UIScreen.main.bounds)
            window?.makeKeyAndVisible()
    
            let navigationController = UINavigationController.init(rootViewController: ViewController())
            window?.rootViewController = navigationController
    
    1. In ViewController:
        override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
    
            navigationController?.navigationBar.prefersLargeTitles = true
            navigationItem.largeTitleDisplayMode = .automatic
        }
    
       override func loadView() {
            super.loadView()
    
            view.addSubview(tableView)
            view.addSubview(loadingView)
    
            NSLayoutConstraint.activate([
                tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
                tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
                tableView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor),
                tableView.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor)
                ])
        }
    

    Make sure your tableView has beed previously added to your view.

    0 讨论(0)
  • 2021-01-31 08:18

    I solved this issue via storyboard

    1. Navigation Controller -> Navigation Bar -> Attributes inspector -> Prefers Large Titles(Checked)
    2. View Controller -> Navigation Item -> Attributes inspector -> Large Title (Automatic or Always checked)
    0 讨论(0)
  • 2021-01-31 08:19

    I recently hit the same issue and none of the suggestions worked for me. Instead, all I needed to do was to invoke sizeToFit(). Sample code:

    private func configureNavigator() {
        guard let navigationController = navigationController else { return }
        navigationController.navigationBar.prefersLargeTitles = true
        navigationItem.largeTitleDisplayMode = .automatic
        navigationController.navigationBar.sizeToFit()
    }
    

    I hope this helps!

    0 讨论(0)
  • 2021-01-31 08:19

    I ran into the same issue and found that it’s usually best to set the prefersLargeTitles property from the view controller or object that sets it up, and to do so before it is presented.

    For instance, if the view controller in question is shown upon app launch:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
        let window = UIWindow(frame: UIScreen.main.bounds)
    
        let someViewController: UIViewController = CustomViewController()
    
        let theNavController = UINavigationController(rootViewController: someViewController)
        theNavController.navigationBar.prefersLargeTitles = true
    
        window.rootViewController = theNavController
        window.makeKeyAndVisible()
    
        return true
    }
    

    or if presenting a particular view controller:

    let someViewController: UIViewController = CustomViewController()
    
    let theNavController = UINavigationController(rootViewController: someViewController)
    theNavController.navigationBar.prefersLargeTitles = true
    
    present(theNavController, animated: true, completion: nil)
    

    I found this method to be a more sure-fire way to ensure that the navigation title is displayed accordingly. Hope this helps! :)

    0 讨论(0)
  • 2021-01-31 08:19

    I have wasted some considerable amount of time on this as prefersLargeTitle saga works on some view controllers as expected and with some it produces the same issue above.

    Solution for me was to uncheck Extended Edges Under Top Bars in IB - for those view controllers who show large title momentarily until the contents of the table view are loaded then navigation bar jumps back up to regular size. It only shows the large title when scrolling the table view down.

    This is backward compatible with iOS 10 and does not leave any empty space above the first row in the table view.

    I had checked prefersLargeTitle on the navigation controllers attributes inspector only in IB - nothing in code. Same for largeTitleDisplayMode = .always

    As for why this happens with some view controllers and not others, I have absolutely no idea!

    0 讨论(0)
提交回复
热议问题