- WillMove (Toparentviewcontroller:)
- Call timing
- Call
addChildViewController(_:) in Money will be automatically called
- Called
removeFromParentViewController() before it is invoked manually.
Didmove (Toparentviewcontroller:)
- Call timing
- Called
removeFromParentViewController() after the method is automatically called
- Called
addChildViewController(_:) after the method is invoked manually.
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。
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