13

I have a normal view controller that is embedded in a navigation controller. In this view controller, I have a table view that is using the constraints of the safe area. (I don't use a table view controller)

The navigation controller is set to prefer large titles and the mode is set to .always. In beta 2 this worked perfectly, So when I came in the title was large and when I scrolled down it became small (Like the normal one). But since beta 3 this doesn't work anymore.

Anyone know how to turn this back on, or how to make it so when I scroll the table view it will become smaller. Like the behaviour of all the new iOS 11 apps?

Or is this a bug in the current version of swift 4/iOS 11 but the apps like messenger and settings still work this way.

Thanks in advance.

Jippe Joosten
  • 403
  • 1
  • 3
  • 16

5 Answers5

20

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!

Jippe Joosten
  • 403
  • 1
  • 3
  • 16
12

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
}
pkamb
  • 33,281
  • 23
  • 160
  • 191
Sergio Trejo
  • 632
  • 8
  • 23
  • I did this on the Storyboard I attach the two images showing how hierarchy should be, edited ... I added code I used to set Large titles – – Sergio Trejo Nov 26 '17 at 07:17
  • @SergioTrejo but how do you do to have the button under the table? In my case I have a view that must be under the a scrollView because is a background. Thanks! – vicente.fava Mar 17 '18 at 00:56
  • Thank you! that was it for me! – Jelle Dec 21 '18 at 14:24
3
(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y > 0) { //20
        [self.navigationController.navigationBar setPrefersLargeTitles:NO];
    } else {   
        [self.navigationController.navigationBar setPrefersLargeTitles:YES];
    }    
}
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
pideni
  • 41
  • 1
0

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

navigationController?.navigationBar.prefersLargeTitles = true
Nemanja
  • 194
  • 10
  • 3
    Yes so I do this and the large title shows but never becomes small when I scroll down. It always stays big but when I scroll up and I’m at the top the title becomes even bigger. So the constraints also work properly, it’s just since beta 3 it doesn’t become small when I scroll down. – Jippe Joosten Jul 17 '17 at 12:40
0

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
Mark Suman
  • 10,430
  • 2
  • 27
  • 23