Prevent UINavigationBar popViewController animation

筅森魡賤 提交于 2019-12-12 08:58:33

问题


I have the following problem: I have overridden popViewControllerAnimated:(BOOL)animated of UINavigationController because I would like to have a custom animation. The code is as follows:

- (UIViewController *)popViewControllerAnimated:(BOOL)animated 
{
    UIViewController *poppedCtrl = [super popViewControllerAnimated:NO];
    [((customViewController *) self.topViewController) doCustomAnimation];
    return poppedCtrl;
}

Unfortunately the UINavigationBar seems to ignore that I explicitly disable the built in animation and it is still animated.

What do I have to do to also prevent the animation of the navigation bar?


回答1:


After some reading and also some experimentation I finally found out what needs to be done to achieve the desired behavior.

To prevent the navigation bar from being animated it is not sufficient to override (UIViewController *)popViewControllerAnimated:(BOOL)animated.

It is also necessary to create a custom navigation bar and override (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated:

- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated {
    return [super popNavigationItemAnimated:NO];
}

Of course this custom navigation bar must also be the one which is used (I just replaced the navigation bar which is used by my navigation controller in the interface builder).




回答2:


If anyones looking to disable push animation - this works for me, by overrideing this method on UINavigationBar:

- (void)pushNavigationItem:(UINavigationItem *)item {
    NSMutableArray* items = [[self items] mutableCopy];
    [items addObject:item];
    self.items = items;
}


来源:https://stackoverflow.com/questions/8531165/prevent-uinavigationbar-popviewcontroller-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!