我正在开发一个应该只支持横向的 iPad 应用程序。我使用这两种方法将新的 subview Controller 添加到我的容器 View Controller :
- (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];
}];
}
}
问题是 subview Controller 的 View 是以纵向添加的,它弄乱了 View ,如下图所示:
绿色 View 是 subview Controller 的 View ,如您所见,它是在纵向模式下添加的。它不是占据整个黄色 View (这是容器 View ,它占据灰色顶栏下方的 View Controller 的整个框架),而是以纵向模式添加,我不明白为什么。
PS:我尝试覆盖苹果文档中编写的shouldAutomaticallyForwardRotationMethods
和shouldAutomaticallyForwardAppearanceMethods
,但没有结果。
最佳答案
正如您将在 Apple's documentation 中看到的那样,您需要手动设置 subview Controller 的框架。
关于iOS 容器 View Controller 添加 child 的纵向 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19135523/