来自导航抽屉的 UIViewController 之间的转换

transition between UIViewController from navigation drawer

我正在使用 Swift 3. 我搜索了这个并找到了解决方案

navigationDrawerController?.TransitionFromRootViewController

但是当我使用这一行时它说 TransitionFromRootViewController 不是函数。

所以我尝试使用

navigationDrawerController?.transition(from: RootViewController(), to: destViewController(), duration: 0.2, options: .transitionCrossDissolve, animations: nil, completion: nil)

但它显示错误:

"child view controller must have a common parent view controller when calling transitionfrom view controller"

有人可以帮帮我吗?如果有人可以推送带有切换的导航抽屉的示例,那就太好了。

这是我发布到 NavigationDrawerController example project in the programmatic directory, Material 2.1.2.

的解决方案

它展示了如何使用多个导航控制器进行转换,以及如何单独进行转换。

import UIKit
import Material

class LeftViewController: UIViewController {
private var transitionButton: FlatButton!

open override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = Color.blue.base

    prepareTransitionButton()
}

@objc
internal func handleTransitionButton() {
    // Transition the entire NavigationDrawer rootViewController.
    // navigationDrawerController?.transition(to: TransitionedViewController(), completion: closeNavigationDrawer)

    // Transition the ToolbarController rootViewController that is in the 
    // NavigationDrawer rootViewController.
    (navigationDrawerController?.rootViewController as? ToolbarController)?.transition(to: TransitionedViewController(), completion: closeNavigationDrawer)
}

internal func closeNavigationDrawer(result: Bool) {
    navigationDrawerController?.closeLeftView()
}

private func prepareTransitionButton() {
    transitionButton = FlatButton(title: "Transition VC", titleColor: Color.white)
    transitionButton.addTarget(self, action: #selector(handleTransitionButton), for: .touchUpInside)

    view.layout(transitionButton).horizontally().center()
}
}

您可以在 GitHub issue-546

中找到对讨论的参考

祝一切顺利!