自定义从VC到视图内的另一个VC的转换

时间:2015-07-07 18:17:25

标签: ios swift

我有这个代码将VC更改为视图中的另一个VC(containerView)。代码有效,但我如何在两个视图之间设置转换?

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

        })

1 个答案:

答案 0 :(得分:0)

要在VC之间进行转换,您可以在视图中显示每个VC,并在容器视图中将它们设置为视图内外的动画。这些方面的东西:

setRetainInstance(true)