第一次绘制时 pageViewController 中的 ios subview 定位不正确

标签 ios view positioning subview

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

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);
}

最佳答案

解决了问题。问题不在于显示分屏的 View Controller ,而是我的自定义 pageviewcontroller。

我在 -viewDidLoad 而不是 -viewDidAppear 中添加了 pageviewcontroller 子项。不同之处在于 -viewDidLoad 没有正确的父 View 尺寸,因此所有 subview 的计算都不正确。

关于第一次绘制时 pageViewController 中的 ios subview 定位不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13464762/

相关文章:

ios - 当我加载我的应用程序时,我的音乐播放器停止播放音乐

c# - MonoTouch 到 Objective-C

objective-c - 使用带有 UIImageView 的 touchesEnded 时遇到问题

css - 用户滚动页面后将 div 保持在原位

c# - 我想在 C# 中将两个表单并排放置

jQuery:获取给定 'y' 位置上方的元素

ios - 在选择单元格之前,不会显示 URL 中的 Swift 表格 View 图像

iphone - 变换后获取帧值的最佳方法?

html - 两步 View 模式: XSLT vs.对象图

swift - 如何在 swift 中打开另一个关于动画完成的 View ?