如何使用transitionFromViewController:在viewController和navigationController之间进行转换?

时间:2015-10-08 07:27:44

标签: ios swift uiviewcontroller uinavigationcontroller

我创建了一个项目来做一些测试。我发现当我使用transitionFromViewController:UIViewController转换为UINavigationController时,完成块的参数始终为false。 为什么会发生这种情况? 我在containerViewController的viewDidLoad中创建了一个目标viewController的实例,这个目标viewController是一个UINavigationController,然后我将它添加为containerViewController的childViewController:

self.fourthVC = UIStoryboard.VCWithSpecificSBAndSBID(SBName: "Main", SBID: "FourthNav") as? UINavigationController
self.addChildViewController(self.fourthVC!)

这是动画表演:

println("will show fouthVC")
self.show(self.fourthVC, fromVC: self.currentVC, completion: {
    finished in
    if finished {
        // Because code below is not executed, so I can't continue to make transition between viewControllers.
        println("transition from currentVC to fourthVC completed")
        self.currentVC = self.thirdVC!
    } else {
        println("transition from currentVC to fourthVC is not finished")
    }
})

当我运行此代码时,它打印出"从currentVC到fourthVC的转换未完成"在Xcode的调试窗口中,它表示完成块的参数(已完成)的值为false(已完成为false),但这怎么可能发生?我该如何解决?

功能展示的定义是:

extension UIViewController {
func show(toVC: UIViewController?, fromVC: UIViewController?, completion: ((Bool) -> Void)? ) {
    let screenBounds: CGRect = UIScreen.mainScreen().bounds
    let finalToFrame: CGRect = screenBounds
    let finalFromFrame: CGRect = CGRectOffset(finalToFrame, -screenBounds.size.width, 0)
    self.transitionFromViewController(fromVC!, toViewController: toVC!, duration: 0, options: nil, animations: {
        toVC!.view.frame = finalToFrame
        }, completion: completion)
}}

有关此问题的示例如下:https://github.com/clwm01/RCTools

0 个答案:

没有答案