- willMove(toParentViewController:)
- 調(diào)用時(shí)機(jī)
- 調(diào)用
addChildViewController(_:)
以錢(qián)會(huì)被自動(dòng)調(diào)用 - 調(diào)用
removeFromParentViewController()
之前被手動(dòng)調(diào)用纷跛。
- 調(diào)用
- didMove(toParentViewController:)
- 調(diào)用時(shí)機(jī)
- 調(diào)用
removeFromParentViewController()
方法之后被自動(dòng)調(diào)用 - 調(diào)用
addChildViewController(_:)
方法之后被手動(dòng)調(diào)用验辞。
- 調(diào)用
- 把子vc的view加到父vc的view上
[self addChildViewController:_startMapViewController]; // 1 作為子VC,會(huì)自動(dòng)調(diào)用子VC的willMoveToParentViewController方法霸琴。
[topContainer addSubview:_startMapViewController.view]; // 2 子VC的view被作為subview添加到第一個(gè)viewContainer中
[_startMapViewController didMoveToParentViewController:self]; // 3 子VC被通知擁有一個(gè)父VC工闺。
- 把子VC的view移除
[fromController willMoveToParentViewController:nil];//
調(diào)用轉(zhuǎn)場(chǎng)方法或者[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.
這個(gè)函數(shù)首先把第二個(gè)VC的view加到父vc的字view上,然后執(zhí)行動(dòng)畫(huà)故河,最后把第一個(gè)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
}];
}
這個(gè)函數(shù)是把fromVC及其View移除匾灶,toVC及其View加到界面上去棱烂。
- fromVC移除
[fromController willMoveToParentViewController:nil]; //函數(shù)調(diào)用前
[fromController removeFromParentViewController]; // 動(dòng)畫(huà)block中
[fromController.view removeFromSuperView] //動(dòng)畫(huà)block之后
- toVC加到界面上
[self addChildViewController:toController]; //函數(shù)調(diào)用前
[self.view addSubView:toController.view] //動(dòng)畫(huà)block之前
[toController didMoveToParentViewController:self]; // block之中