2013-10-02 158 views
0

我正在開發一款僅支持橫向方向的iPad應用。我用這兩種方法到一個新的子視圖控制器添加到我的容器視圖控制器:iOS容器視圖控制器在縱向方向上添加兒童視圖

如圖

的問題是,子視圖控制器的觀點是縱向且將其打亂了意見

- (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]; 
           }]; 


    } 
} 
下面的圖片:

enter image description here

綠色的觀點是子視圖控制器,你可以看到在縱向模式中添加的視圖。它不是佔據整個黃色視圖(這是容器視圖,它佔據了視圖控制器的整個框架,位於灰色頂部欄下方),而是以縱向模式添加,我無法弄清楚原因。

PS:我試圖覆蓋shouldAutomaticallyForwardRotationMethodsshouldAutomaticallyForwardAppearanceMethods在蘋果文檔中寫入,但沒有結果。

回答

相關問題