iOS 11 prefersLargeTitles not updating until scroll

前端 未结 24 2393
轻奢々
轻奢々 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: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! :)

提交回复
热议问题