5

I want to add a banner to the navigation bar, but by increasing the height of it. I want to copy the design and behaviour of an artist page in the Apple Music app:

Apple Music

It behaves just like a normal Large Title would, except for that it has been moved down, it has a sticky UIImageView behind it and it returns its background when the user scrolls down far enough. You can fire up Apple Music, search for an artist and go to their page to try it out yourself.

I've tried a bunch of things like setting the frame on the UINavigationBarLargeTitleView, and the code from this answer: https://stackoverflow.com/a/49326161/5544222

I already got a hold of the UINavigationBarLargeTitleView and its UILabel using the following code:

func setLargeTitleHeight() {
    if let largeTitleView = self.getLargeTitleView() {
        if let largeTitleLabel = self.getLargeTitleLabel(largeTitleView: largeTitleView) {
            // Set largeTitleView height.
        }
    }
}

func getLargeTitleView() -> UIView? {
    for subview in self.navigationBar.subviews {
        if NSStringFromClass(subview.classForCoder).contains("UINavigationBarLargeTitleView") {
            return subview
        }
    }
    return nil
}

func getLargeTitleLabel(largeTitleView: UIView) -> UILabel? {
    for subview in largeTitleView.subviews {
        if subview.isMember(of: UILabel.self) {
            return (subview as! UILabel)
        }
    }
    return nil
}
Zandor Smith
  • 558
  • 6
  • 25
  • Did you end up with a solution? Looking for something similar. – Savjee Aug 07 '19 at 12:40
  • @Savjee, I did, I programmed my own solution with a little help from my WhiteNavigationController library to hide the stock navbar gradually. I am planning on creating an open-source library out of it but I'm currently on vacation. https://github.com/Zandor300/WhiteNavigationController – Zandor Smith Aug 09 '19 at 08:23
  • I think this one is the right choice for you. https://github.com/romansorochak/ParallaxHeader – Kamani Jasmin Aug 10 '19 at 09:16
  • This is Parallax tableview, https://github.com/maxep/MXParallaxHeader – Prashant Tukadiya Aug 13 '19 at 11:20

1 Answers1

-1

Initially put a view with image and label and play button. Then clear the navigation bar it will show the image below it by

self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController!.navigationBar.shadowImage = UIImage()
    self.navigationController!.navigationBar.isTranslucent = true

later when you scroll up you have to handle it manually and again show the navigation with title.