在第一次绘制时,pageViewController中的ios子视图定位不正确

时间:2012-11-20 00:20:22

标签: ios view positioning subview

我有一个嵌套在pageviewcontroller中的viewcontroller,我希望将其细分为两个部分(顶部+底部)。我正确地为各个视图(下面的代码)分配帧,但第一次渲染时是不正确的。当我向后滑动然后再次返回时,渲染的屏幕是正确的。知道发生了什么事吗?

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 个答案:

答案 0 :(得分:1)

找出问题所在。问题不在于显示分屏的视图控制器,而是我的自定义pageviewcontroller。

我在-viewDidLoad而不是-viewDidAppear中添加了pageviewcontroller子项。区别在于-viewDidLoad没有超视图的正确尺寸,因此所有子视图的计算都不正确。