2015-11-06 81 views

回答

0

是的。你可以在Apple Docs中阅读。

考虑您的containerView目前只有一个视图 - 控制,这里是一个非常简单的例子:

func loadVCWithId(idToLoad: String){ 
    childViewControllers[0].willMoveToParentViewController(nil) 
    childViewControllers[0].view.removeFromSuperview() 
    childViewControllers[0].removeFromParentViewController() 

    let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier(idToLoad) 

    UIView.transitionWithView(yourContainer, duration: 0.5, options: UIViewAnimationOptions.TransitionFlipFromRight, animations: {self.yourContainer.addSubview((secondViewController?.view)!)}, completion: nil) 


    secondViewController!.view.frame = firstContainer.bounds 
    // do initialization of secondViewController here 
    secondViewController?.didMoveToParentViewController(self) 
} 

loadVCWithId(idToLoad:String)是您的主视图控制器中的一个方法。

在这个代码片段中,我删除容器的当前内容(可能不是访问索引0的最佳方式,但为了这个例子,这应该足够了),通过ID实例化一个新的ViewController一个出现在我的故事板中,但不能访问),为过渡设置动画,并将新的VC添加到容器中。

希望这会有所帮助。

0

这是我的解决方案

可能有助于第一我对childViewController创建一个协议

protocol ChildViewControllerDelaget 

{ 

    func performForSegue(SegueIdentifier:String) 

} 

class ChildViewController: UIViewController { 

    var delaget:ChildViewControllerDelaget? 

    override func viewDidLoad() { 
     super.viewDidLoad() 

    } 

    init() 
    { 

    } 


@IBAction func myAction(sender: AnyObject) { 

if delaget != nil { 
deleget.performForSegue("mySegueIdentifier") 
} 

} 

和MainViewController

class ViewController: UIViewController,ChildViewControllerDelaget { 


    override func viewDidLoad() 

    { 

     super.viewDidLoad() 

     let child = ChildViewController() 

     child.delaget = self 



    } 

    func performForSegue(segueIdentifier:String) 

    { 

     self.performSegueWithIdentifier(segueIdentifier, sender: nil) 

    } 

} 
相关问题