iOS 容器 View Controller 添加 child 的纵向 View

标签 ios objective-c uiviewcontroller orientation containment

我正在开发一个应该只支持横向的 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 ,如下图所示:

enter image description here

绿色 View 是 subview Controller 的 View ,如您所见,它是在纵向模式下添加的。它不是占据整个黄色 View (这是容器 View ,它占据灰色顶栏下方的 View Controller 的整个框架),而是以纵向模式添加,我不明白为什么。

PS:我尝试覆盖苹果文档中编写的shouldAutomaticallyForwardRotationMethodsshouldAutomaticallyForwardAppearanceMethods,但没有结果。

最佳答案

正如您将在 Apple's documentation 中看到的那样,您需要手动设置 subview Controller 的框架。

关于iOS 容器 View Controller 添加 child 的纵向 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19135523/

相关文章:

uiviewcontroller 黑色

ios - 无法使用 ((_) -> _) 类型的参数列表调用过滤器

iOS Firebase 从子节点检索数据总是 nil

ios - 当我向专用于加载更多结果功能的 UITableViewController 添加额外的行时,我的 iOS7 应用程序崩溃

objective-c - Cocoa 中*您的*常量/静态变量是否有任何有用的命名约定?

iphone - 从子 UIViewController 到父 UIViewController 的通信

ios - 如何将用于共享内容的 LinkedIn API 从 OAuth 1.2 转换为 OAuth2

ios - 如何存储、检索选中或未选中的单元格

iphone - 如何使用 NSSortDescriptor 对 NSMutableArray 进行排序?

ios在运行时更改 Storyboard默认 View Controller