码迷,mamicode.com
首页 > 其他好文 > 详细

View-Controller-Containment

时间:2017-01-14 11:12:55      阅读:164      评论:0      收藏:0      [点我收藏+]

标签: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

标签:sel   duration   nil   block   start   anim   函数   bool   for   

原文地址:http://www.cnblogs.com/huahuahu/p/ViewControllerContainment.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!