我有这段代码,将一个VC更改为视图(containerView)内的另一个VC。该代码有效,但是如何在两个视图之间设置过渡?

var childVC: UIViewController?
@IBOutlet weak var containerView: UIView!

func ChangeViewController() {
    childVC?.willMoveToParentViewController(nil)
    childVC?.view.removeFromSuperview()
    childVC?.removeFromParentViewController()
    childVC = storyboard?.instantiateViewControllerWithIdentifier("identifier") as? UIViewController
    if let childVC = childVC {
        addChildViewController(childVC)
        childVC.view.frame = containerView.bounds
        containerView.addSubview(childVC.view)
        childVC.didMoveToParentViewController(self)
    }
}


我试过了,但是没用:

let oldView = childVC?.view
UIView.transitionFromView(oldView!, toView: childVC.view, duration: 2, options: UIViewAnimationOptions.TransitionFlipFromLeft, completion: { (succeed) -> Void in

        })

最佳答案

要在VC之间切换,可以在视图中显示每个VC,并在容器视图中对其进行动画显示。遵循以下原则:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self.containerView];

// Your animations here

[UIView commitAnimations];

关于ios - 在 View 内从VC到另一个VC的自定义过渡,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31276365/

10-12 13:37