2012-11-20 52 views
1

我有一個viewcontroller嵌套在pageviewcontroller中,我想要細分爲兩部分(top + bottom)。我正確地分配了相應視圖的幀(下面的代碼),但是第一次渲染的幀不正確。當我滑開然後再回來時,渲染後的屏幕就是正確的。任何想法發生了什麼?在第一次繪製時,ios子視圖在pageViewController中的定位不正確

enter image description here

enter image description here

-(void) viewDidLoad 
{ 

self.controller1 = [self.storyboard  
    instantiateViewControllerWithIdentifier: @"controller1"]; 
self.controller2 = [self.storyboard 
    instantiateViewControllerWithIdentifier:@"controller2"]; 

[self.view addSubview:self.controller1.view]; 
[self.view addSubview:self.controller2.view]; 

[self addChildViewController:self.controller1]; 
[self addChildViewController:self.controller2]; 
} 

- (void)viewWillAppear 
{ 
UIInterfaceOrientation orientation = self.interfaceOrientation; 
BOOL navigationBarHidden = [self.navigationController isNavigationBarHidden]; 
CGRect navigationBarFrame = self.navigationController.navigationBar.frame; 
CGRect screenBounds = [[UIScreen mainScreen] bounds]; 
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame]; 
CGRect viewSize = self.view.frame;  

self.controller1.view.frame = 
    CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.width); 

self.controller2.view.frame = 
    CGRectMake(0, screenBounds.size.width, 
          screenBounds.size.width, applicationFrame.size.height - screenBounds.size.width); 
} 

回答

1

想通了這個問題。問題不在於顯示分屏的視圖控制器,而是我的自定義pageviewcontroller。

我在-viewDidLoad中添加了pageviewcontroller子項,而不是-viewDidAppear。不同之處在於-viewDidLoad沒有超視圖的正確維度,因此所有的子視圖都被錯誤地計算出來了。

相關問題