我已经构建了一个 UIViewController 来包含另外两个 UIViewController。我想在 UINavigationBar 中使用 UISegment 做的是在两个视图之间切换。当用户完成他们点击“完成”并返回到 RootViewController。我得到了这个工作,除了 UIViewControllers 占用整个屏幕的大小,所以顶部被 UINavigationBar 覆盖。它们不会适应 UINavigationBar 下的空间。我一直在尝试不同的技术,但没有成功。
我已经在 ChildUIViewControllers 中尝试过但没有成功
self.edgesForExtendedLayout = UIRectEdgeNone;
这是我的代码:
RootViewController 调用容器
ContainerController *controller = [[ContainerController alloc] init]
[self.navigationController pushViewController:controller animated:YES];
容器代码
- (void)viewDidLoad {
[super viewDidLoad];
UIViewController *vc = [self getCurrentViewController]; // Returns Current ViewController to Display
[self addChildViewController:vc];
vc.view.frame = self.view.bounds;
[self.view addSubview:vc.view];
self.currentViewController = vc;
}
-(UIViewController *)getCurrentViewController{
UIViewController *vc;
switch ([[NSUserDefaults standardUserDefaults] integerForKey:@"currentView"]) {
case kView1:{
vc = (ViewController1 *)[[ViewController1 alloc] init];
}break;
case kView2:{
vc = (ViewController2 *)[[ViewController2 alloc] init];
}break;
}
return vc;
}
- (void)segmentedControlIndexChanged:(id)sender{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:[NSNumber numberWithInt:[sender selectedSegmentIndex]] forKey:@"currentView"];
[userDefaults synchronize];
UIViewController *vc = [self getCurrentViewController];
[self addChildViewController:vc];
[self transitionFromViewController:self.currentViewController toViewController:vc duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
[self.currentViewController.view removeFromSuperview];
vc.view.frame = self.view.bounds;
[self.view addSubview:vc.view];
} completion:^(BOOL finished) {
[vc didMoveToParentViewController:self];
[self.currentViewController removeFromParentViewController];
self.currentViewController = vc;
}];
self.navigationItem.title = vc.title;
}
有人知道问题是什么吗?谢谢。