I am trying to create a similar animation to the Apple TV app - specifically this animation
Here are just some screenshots of the different states of this transition
1 - No title, a back button, add button and share button in white color
2 - After a certain point of scrolling, we can see the color of the buttons in the navigation bar changing
3 - After scrolling some more, a title appears in the nav bar, the buttons change color and the nav bar itself becomes translucent
How can such an animation be achieved in SwiftUI ?
The only thing I can think of at the moment would be to use a UIScrollView within swiftUI so that we can make use of the delegates it offers. However, even beyond this, I am uncertain of how to achieve such animations in UIKit as well.
However, how can we apply these different navigation bar animations in SwiftUI of the:
- Navigation Style from opaque to translucent
- The color of the different buttons
- The navigation bar title
I have a similar thing trying to replicate the Spotify album view where I have a Sticky Header that fades out after the user scrolls up. I have modified it a bit to give you an idea on how to reach the translucency effect. You can use the Material.ultraThinMaterial or similar materials from that struct. Here' some documentation from Apple:
And now to the fun part, the stikcy header. My code will work on iOS 16+. I also added some comment to indicate you were to modify header colors. As you can see the back arrow becomes blue after a certain point. This was just to give you an idea. Code:
Apart from missing images and some color it should work out of the box. You can use it like this:
Result:
Let me know if this can work for you!