View-controller-containment

Source: Internet
Author: User

  1. WillMove (Toparentviewcontroller:)
    • Call timing
    • Call addChildViewController(_:) in Money will be automatically called
    • Called removeFromParentViewController() before it is invoked manually.
  2. Didmove (Toparentviewcontroller:)

    • Call timing
    • Called removeFromParentViewController() after the method is automatically called
    • Called addChildViewController(_:) after the method is invoked manually.
  3. The view of the VC is added to the parent 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. View removal from VC

    [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.

This function first adds the view of the second VC to the parent VC's Word view, then performs the animation, and finally removes the view of the first VC from the 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                            }];}

This function removes Fromvc and its view, and TOVC and its view are added to the interface.

    • FROMVC Removal

      [fromController willMoveToParentViewController:nil]; //函数调用前[fromController removeFromParentViewController];    //  动画block中[fromController.view removeFromSuperView] //动画block之后
    • TOVC added to the interface

      [self addChildViewController:toController]; //函数调用前[self.view addSubView:toController.view] //动画block之前       [toController didMoveToParentViewController:self];  //  block之中

View Controller Containment

View-controller-containment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.