是否可以使用 NavigationBarViewController 作为 UINavigationController 将视图控制器推送到堆栈上

Is it possible to use NavigationBarViewController as UINavigationController to push View Controllers on the stack

我正在努力用 https://github.com/CosmicMind/Material 替换 UINavigationControllers 和其他 iOS 标准 UI 类,尤其是 NavigationBarViewController。我知道在引擎盖下它使用 parent/child 控制器设置来在其自身上呈现新的视图控制器,但我无法弄清楚如何才能将基本导航 VC 推送到堆栈上并打开后退按钮左回去。浏览 NavigationBarViewController 的源代码似乎没有办法做到这一点。是否可以使用 NavigationBarViewController 来实现?

要转换作为 NavigationBarViewController 主体的 mainViewController,您可以使用

transitionFromMainViewController

方法。它支持动画选项,但不支持 MoveIn 或 Push 动画。

为此,您需要使用 Material动画 API 中可用的过渡方法。

示例:

let vc: HashtagListViewController = HashtagListViewController()
    vc.view.layer.addAnimation(MaterialAnimation.transition(.MoveIn, direction: .Right), forKey: kCATransitionFromRight)

    navigationBarViewController?.transitionFromMainViewController(vc)

基本上您正在做的是利用 UIViewController.view.layer 的过渡动画。

如果您不想做那种努力,

transitionFromMainViewController

提供了一些不错的开箱即用动画供您使用。

在 Material 的未来版本中,将会有一个完整的 NavigationViewController 堆栈来完成您所要求的一切。

更新

在Material1.36.0中,新增了两个类,NavigationBar和NavigationController。 NavigationController 是 UINavigationController 的子类,因此在项目堆栈上推送和弹出 UIViewController 的所有功能都是相同的,同时能够轻松自定义控制器的外观。

示例 App 项目展示了如何使用它。