View-Controller-Containment

來源:互聯網
上載者:User

標籤:sel   duration   nil   block   start   anim   函數   bool   for   

  1. willMove(toParentViewController:)
    • 調用時機
    • 調用addChildViewController(_:)以錢會被自動調用
    • 調用removeFromParentViewController()之前被手動調用。
  2. didMove(toParentViewController:)

    • 調用時機
    • 調用removeFromParentViewController()方法之後被自動調用
    • 調用addChildViewController(_:)方法之後被手動調用。
  3. 把子vc的view加到父vc的view上

    [self addChildViewController:_startMapViewController];          //  1  作為子VC,會自動調用子VC的willMoveToParentViewController方法。[topContainer addSubview:_startMapViewController.view];         //  2 子VC的view被作為subview添加到第一個viewContainer中[_startMapViewController didMoveToParentViewController:self];   //  3 子VC被通知擁有一個父VC。
  4. 把子VC的view移除

    [fromController willMoveToParentViewController:nil];//調用轉場方法或者[fromController.view removeFromSuperView][fromController removeFromParentViewController];    // 

5 transition(from:to:duration:options:animations:completion:)

This method adds the second view controller'??s view to the view hierarchy and then performs the animations defined in your animations block. After the animation completes, it removes the first view controller'??s view from the view hierarchy.

這個函數首先把第二個VC的view加到父vc的字view上,然後執行動畫,最後把第一個vc的view從view hierarchy中移除。

{    toController.view.frame = fromController.view.bounds;                           //  1    [self addChildViewController:toController];                                     //      [fromController willMoveToParentViewController:nil];                            //      [self transitionFromViewController:fromController                      toViewController:toController                              duration:0.2                               options:direction | UIViewAnimationOptionCurveEaseIn                            animations:nil                            completion:^(BOOL finished) {                                [toController didMoveToParentViewController:self];  //  2                                [fromController removeFromParentViewController];    //  3                            }];}

這個函數是把fromVC及其View移除,toVC及其View加到介面上去。

  • fromVC移除

    [fromController willMoveToParentViewController:nil]; //函數調用前[fromController removeFromParentViewController];    //  動畫block中[fromController.view removeFromSuperView] //動畫block之後
  • toVC加到介面上

    [self addChildViewController:toController]; //函數調用前[self.view addSubView:toController.view] //動畫block之前       [toController didMoveToParentViewController:self];  //  block之中

View Controller Containment

View-Controller-Containment

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.