添加
- 初始化控制器
- 添加控制器
- 调整添加View
- didMoveToParentViewController通知
-(void)addChildVc:(UIViewController*)vc view:(UIView *)view {
BOOL needAddToParent = !vc.parentViewController;
if (needAddToParent) [self addChildViewController:vc];
vc.view.frame = view.bounds;
[view addSubview:vc.view];
if (needAddToParent) [vc didMoveToParentViewController:self];
}
删除
- willMoveToParentViewController通知
- 是否加载View,加载则移除View
- 移除控制器
-(void)removeChildVc:(UIViewController*)vc {
[vc willMoveToParentViewController:nil];
if (![vc isViewLoaded]) {
[vc removeFromParentViewController];
} else {
[vc.view removeFromSuperview];
[vc removeFromParentViewController];
}
}