Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shrink large title when scrolling (not UITableViewController) iOS 11

Tags:

I have got a View Controller embedded in a Navigation Controller with prefers large titles option set to true; inside the View Controller there’s a Scroll View.

I want to make the nav bar shrink when scrolling.

How could I achieve this?

Xcode 9, Swift 4, iOS 11

like image 520
Jonathan Solorzano Avatar asked Oct 12 '17 07:10

Jonathan Solorzano


People also ask

How do I align scrollable content to the top of view?

The scrollable content top constraint must align to the top of the view controller’s view. The scrollable content (or its container) must be the first subview in the view controller’s z-axis. If you are using a UIRefreshControl, make sure to use the standard way to assign it to the scrollable content.

Why does the large title of a Tableview not hide automatically?

If the tableView is not the first view, the large title fails to hide automatically. You most likely need to make sure your tableView is the first element in the main view’s subviews array. I hope that this solves your problem.

How do I avoid glitches when creating a scrollable screen?

If you are using a UIRefreshControl, make sure to use the standard way to assign it to the scrollable content. Lastly, if the screen that you create is not complicated, you can always use the UITableViewController and UICollectionViewController to avoid any of these glitches.

How to change the navigation bar style in iOS 13?

If you are using the large title navigation bar, most probably you will want to adjust its styling to suit your needs. This is where the UINavigationBarAppearance APIs introduced in iOS 13 comes in handy. For example, you can use the following code snippet to customize a specific view controller’s navigation bar font and background color.


1 Answers

I have not achieved this using a UIScrollView but I achieved it with other ViewControllers using a UITableView as first view.

If the tableView is not the first view, the large title fails to hide automatically. You most likely need to make sure your tableView is the first element in the main view’s subviews array.

enter image description here

I hope that this solves your problem.

like image 101
93sauu Avatar answered Sep 17 '22 18:09

93sauu