我正在开发一个只支持横向的 iPad 应用程序。我使用这两种方法将新的子视图控制器添加到我的容器视图控制器中:
- (void) assignFirstChildViewController:(UIViewController*)controller
{
self.currentChildViewController = controller;
[self addChildViewController:self.currentChildViewController];
[self.currentChildViewController didMoveToParentViewController:self];
[self.containerView addSubview:self.currentChildViewController.view];
}
- (void)assignNewChildController:(UIViewController *)childViewController
{
id currentChildViewController = self.currentChildViewController;
if(!currentChildViewController){
[self assignFirstChildViewController:childViewController];
}else{
[self.currentChildViewController willMoveToParentViewController:nil];
[self addChildViewController:childViewController];
__weak __block PTSBaseContainerViewController *weakSelf=self;
[self transitionFromViewController:self.currentChildViewController
toViewController:childViewController
duration:1.0
options:0
animations:^{
[UIView transitionFromView:self.currentChildViewController.view toView:childViewController.view duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve completion:NULL];
}
completion:^(BOOL finished) {
[weakSelf.currentChildViewController removeFromParentViewController];
weakSelf.currentChildViewController = childViewController;
[weakSelf.currentChildViewController didMoveToParentViewController:weakSelf];
}];
}
}
问题是子视图控制器的视图是纵向添加的,它会弄乱视图,如下图所示:
绿色视图是子视图控制器的视图,如您所见,它是以纵向模式添加的。它不是占据整个黄色视图(这是容器视图,它占据了灰色顶栏下方视图控制器的整个框架),而是以纵向模式添加的,我不知道为什么。
PS:我尝试过覆盖shouldAutomaticallyForwardRotationMethods
并shouldAutomaticallyForwardAppearanceMethods
按照苹果文档中的说明进行操作,但没有结果。