- (void)selectChildWithItem:(MenuItem *)item
{
// 1.取出之前的控制器
UINavigationController *nav = _childs[item.className];
if (nav == nil) {
Class c = NSClassFromString(item.className);
UIViewController *vc = [[c alloc] init];
vc.view.backgroundColor = kViewBg;
nav = [[UINavigationController alloc] initWithRootViewController:vc];
if (item.modal) {
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:nav animated:YES completion:nil];
return;
}
nav.view.autoresizingMask = UIViewAutoresizingNone;
[nav.view addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragView:)]];
[self addChildViewController:nav];
[_childs setObject:nav forKey:item.className];
}
// 2.如果一样,就返回
if (nav == _currentChild) return;
// 3.移除旧的
[_currentChild.view removeFromSuperview];
// 4.添加新的
CGFloat x = CGRectGetMaxX(_dock.frame);
CGFloat width = 768 - kDockComposeBtnWidthP;
CGFloat height = _dock.frame.size.height;
nav.view.frame = CGRectMake(x, 0, width, height);
[self.view addSubview:nav.view];
_currentChild = nav;
}
IOS在一个ViewController中添加ChildViewController的方法
最新推荐文章于 2022-07-25 18:54:52 发布