chris P chris P - 2 months ago 11
iOS Question

How can I animate a UIView underneath the UINavigationController's view

Right now I'm animating a little banner that sometimes appears directly under the NavigationBar. This UIView lives on a subclass of UINavigationController in my app.

I want to animate the banner view up and under the navigationBar when its time for the view to disappear (as opposed to animating it's height to 0 which can cause wacky things to occur to subviews of the banner). However, it's always animating on top of the navBar.

I've tried sending my view to the back (-sendSubviewToBack:) however, then I don't see it all. Then I tried -bringSubviewToFront, and giving it the navigationBar's view. That didn't work either.

Any ideas?


It sounds like you need to need to be a bit more deliberate with your hierarchy (it's going back too far). Here's a good answer on how to be more specific with your placement. How to send a UIView element backwards in Swift

Specifically, you want to use


and place your view directly beneath the nav bar view that should hide it.

Just a tip, you can bring up the UI debug for some added help.