从导航抽屉中转换UIViewController

时间:2016-10-09 17:04:09

标签: ios swift3 cosmicmind

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

navigationDrawerController?.TransitionFromRootViewController

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

所以我尝试使用

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

但它显示错误:

  

"从视图控制器调用transition时,子视图控制器必须具有公共父视图控制器"

有人能帮帮我吗?如果有人可以通过切换来推动导航抽屉的例子,那就太棒了。

1 个答案:

答案 0 :(得分:1)

以下是解决方案,我将其发布到程序化目录中的NavigationDrawerController example project,材料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

中找到对讨论的引用

一切顺利!