Custom Segue Warning尝试出现" X"在" Y"其视图不在窗口层次结构中

时间:2015-06-21 21:05:02

标签: ios segue

我有一个自定义的segue,以便视图交叉淡入淡出,而不是从下到上显示。

当segue从按钮发生时,它运行良好,但是当我以编程方式执行它时,在UIAlertController之后,我得到“尝试呈现" x"在" y"其视图不在窗口层次结构中。而且,如果我试图放松到演示者视图,应用程序崩溃,或者它只是没有做任何事情。

如果不使用我的自定义segue,我会使用默认" show" segue,我没有收到错误,并且正如预期的那样展开。

这是我的自定义segue(基于http://www.appcoda.com/custom-segue-animations/):

class TransitionManagerFade: UIStoryboardSegue {

    override func perform() {
        // Assign the source and destination views to local variables.
        var unwind = false

        var firstVCView = sourceViewController.view as UIView!
        var secondVCView = destinationViewController.view as UIView!

        if identifier == "SingleDeviceToRootView" || identifier == "MPToRootView" || identifier == "SingleEndToRootView" {

            unwind = true
        }


        // Specify the initial position of the destination view.
        secondVCView.alpha = 0

        // Access the app's key window and insert the destination view above the current (source) one.
        let window = UIApplication.sharedApplication().keyWindow
        window?.insertSubview(secondVCView, aboveSubview: firstVCView)


        // Animate the transition.
        UIView.animateWithDuration(1.5, animations: { () -> Void in

            firstVCView.alpha = 0
            secondVCView.alpha = 1

            }) { (Finished) -> Void in

                if unwind {

                    self.sourceViewController.dismissViewControllerAnimated(false, completion: nil)

                } else {
                    self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
                        animated: false,
                        completion: nil)
                }
        }
    }
}

0 个答案:

没有答案