Hide large title when scrolling up

こ雲淡風輕ζ 提交于 2019-12-01 03:29:58

For me, it was that if you set the boolean "Prefers Large Titles" in the storyboard to true it will stay large, if you turn this on by code it works as expected!

I found a workaround on this site basically, if the tableView (or element that has scroll)is not the first view in your view hierarchy, the large title fails to hide automatically.

Example that will NOT work Example that will work

https://markusbodner.com/2017/10/08/fix-large-navigation-bar-title-not-hiding-on-scroll-in-ios-11/

I added on the view willAppear:

        if #available(iOS 11.0, *) {
        navigationController?.navigationBar.prefersLargeTitles = true
    } else {
        // Fallback on earlier versions
    }
pideni
(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y > 0) { //20
        [self.navigationController.navigationBar setPrefersLargeTitles:NO];
    } else {   
        [self.navigationController.navigationBar setPrefersLargeTitles:YES];
    }    
}

Check "Prefers Large Titles" for your navigation bar in IB, or use:

navigationController?.navigationBar.prefersLargeTitles = true

I'm using a programmatic layout and ran into a similar issue with large titles. I found the solution here: https://stackoverflow.com/a/46692583/131378. In viewDidLoad() I had to toggle the largeTitleDisplayMode off and on again. That was the correct combination that got the large titles working with scrolling:

self.navigationItem.largeTitleDisplayMode = .never
self.navigationItem.largeTitleDisplayMode = .always
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!