2015-11-06 80 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) 

    } 

} 
相關問題