防止自定义容器中的 UINavigationBar 动画

Prevent UINavigationBar animation in custom container

我按照本指南 Implementing a Container View Controller 制作了一个可以在应用程序中处理 login/logout 的容器。

子视图控制器是:用于登录的 UINavigationController,以及用于应用其余部分的 UITabBarController:

我的问题是 UINavigationBar 的动画很奇怪,我想阻止它的动画:

动画代码基本是这样的(full project code here):

    let current = childViewControllers.first
    current?.willMoveToParentViewController(nil)

    child.securityContainer = self
    addChildViewController(child)

        child.view.frame = newChildOriginFrame

        UIView.transitionWithView(view, duration: 0.3, options: [], animations: {

            child.view.frame = newChildTargetFrame
            current?.view.frame = oldChildTargetFrame

            self.view.addSubview(child.view)

        }, completion: { _ in

            child.didMoveToParentViewController(self)
            current?.view.removeFromSuperview()
            current?.removeFromParentViewController()
            current?.securityContainer = nil
        })

如何防止 UINavigationBar 的动画?

通过将 addSubview 移动到动画块之外来修复它:

let current = childViewControllers.first
current?.willMoveToParentViewController(nil)

child.securityContainer = self
addChildViewController(child)

    child.view.frame = newChildOriginFrame

    view.addSubview(child.view)

    UIView.transitionWithView(view, duration: 0.3, options: [], animations: {

        child.view.frame = newChildTargetFrame
        current?.view.frame = oldChildTargetFrame

    }, completion: { _ in

        child.didMoveToParentViewController(self)
        current?.view.removeFromSuperview()
        current?.removeFromParentViewController()
        current?.securityContainer = nil
    })

(full project source code)