How to change the Push and Pop animations in a navigation based app

前端 未结 25 1473
清酒与你
清酒与你 2020-11-22 12:46

I have a navigation based application and I want to change the animation of the push and pop animations. How would I do that?

Edit 2018

Ther

25条回答
  •  借酒劲吻你
    2020-11-22 12:57

    I found a mildly recursive way to do this that works for my purposes. I have an instance variable BOOL that I use to block the normal popping animation and substitute my own non-animated pop message. The variable is initially set to NO. When the back button is tapped, the delegate method sets it to YES and sends a new non-animated pop message to the nav bar, thereby calling the same delegate method again, this time with the variable set to YES. With the variable is set to YES, the delegate method sets it to NO and returns YES to allow the non-animated pop occur. After the second delegate call returns, we end up back in the first one, where NO is returned, blocking the original animated pop! It's actually not as messy as it sounds. My shouldPopItem method looks like this:

    - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item 
    {
        if ([[navigationBar items] indexOfObject:item] == 1) 
        {
            [expandedStack restack];    
        }
    
        if (!progPop) 
        {
            progPop = YES;
            [navBar popNavigationItemAnimated:NO];
            return NO;
        }
        else 
        {
            progPop = NO;
            return YES;
        }
    }
    

    Works for me.

提交回复
热议问题