I have enabled Large Title
in my navigation bar with automatic Display Mode
, so that it shrinks when user scrolls. Is there a way to get notified when this transition happens? I didn't found any delegate method for this. I have a Right Bar Button Item
with long label which I'd like to hide when Large Title gets shrunk so that the title is perfectly centered.
Asked
Active
Viewed 596 times
3

Adam Bardon
- 3,829
- 7
- 38
- 73
1 Answers
3
Apparently there's no delegate nor any other official way to be notified about this. So my workaround is using ScrollViewDelegate
:
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if let height = navigationController?.navigationBar.frame.size.height, height == 44 {
// handle small title
}
else {
// handle large title
}
}
}
This doesn't work on iPad as the height of navbar is different, but that's intended in my case.
Also keep in mind that scrollViewDidScroll
gets called XX times for a single small scroll, so before doing any updates, check they haven't been done already.

Adam Bardon
- 3,829
- 7
- 38
- 73
-
1You could check the same thing inside `viewDidLayoutSubviews`. It is being called a little bit less often than `scrollViewDidScroll`. – Starsky Sep 04 '20 at 09:30
-
1Is there a better way to not hardcode 44? – ChikabuZ Mar 10 '22 at 18:03