Question

I have a UINavigationBar based app. I've created a custom UIView with some titles and added it as a subview to the navigation bar:

[self.navigationController.navigationBar addSubview:_navbarView];

Everything works ok until I hit the back button in the navigation bar and the UIViewController transition occurs.

The problem is that my custom view doesn't fade away like the others elements in the UINavigationBar, it just stays the same and disappears when the transition is complete. I want it to fade away during the transition like the native elements of the UINavigationBar, is there any way to achieve this?

Was it helpful?

Solution

If you add a subview to the navigation bar, then it will just stay there; the navigation controller doesn't know to do anything special with it. You say your custom view has "some titles" - have you tried doing this instead?

self.navigationItem.titleView = _navbarView;

Then the navigation controller knows that the view should be used in place of your controller's title, and it should animate in and out.

If that doesn't work, you'll need to look at becoming the navigation controller's delegate. Since iOS7, this can get quite complex.

OTHER TIPS

If you need custom navigation bar it could be a good idea to create UINavigationController with custom UINavigationBar

- (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass 

in your navigation bar class you can implement

- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated
{
    if (animated) {
        //your_problem_view animation here
    }
    [super popNavigationItemAnimated];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top