app转到后台后没有调用animationControllerForOperation

时间:2014-10-27 23:52:18

标签: ios objective-c uinavigationcontroller uiviewanimationtransition

我有一个viewcontroller,它使用UINavigationControllerDelegate进行自定义导航推送转换。当你开始动画,按后退按钮等时,一切都很完美。

但是,如果将视图控制器推入堆栈,应用程序的背景,返回,然后按回,则不会调用委托方法animationControllerForOperation。在调试期间,我已经验证了当我们将app返回到前台时仍然正确设置了self.navigationController.delegate,但是从不命中委托回调。有什么想法吗?

 //presenting vc
 - (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                              animationControllerForOperation:(UINavigationControllerOperation)operation
                                           fromViewController:(UIViewController*)fromVC
                                             toViewController:(UIViewController*)toVC
{
    if (operation == UINavigationControllerOperationPush) {
        _animationObject = [LVDashboardExplainerAnimation new];
        _animationObject.presenting = YES;
        return _animationObject;
    } else if (operation == UINavigationControllerOperationPop) {
        _animationObject.presenting = NO;
        return _animationObject;
    }
    return nil;
}

//other VC
- (void)headerTapped {
    self.navigationController.delegate = _navigationDelegate; //correct object
    [self.navigationController popViewControllerAnimated:YES];
}

1 个答案:

答案 0 :(得分:1)

问题源于手动调用viewWillAppear:当应用程序从后台返回时动画。通过调用它,导航委托将调用willShowViewController:animated:但不是navigationController:animationControllerForOperation:或didShowViewController:animated:

出于某种原因,强行调用viewWillAppear会抛出整个事情。即使我们考虑到这一点并将导航委托设置为nil,然后返回正确的对象,功能也无法正常工作。我猜这是SDK中的一个错误,但是现在我们删除了对viewWillAppear的强制调用。