在子控制器中查看控制器帧大小 [英] view controller frame size in child controller

查看:97
本文介绍了在子控制器中查看控制器帧大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现UIViewcontroller包含。在下面的示例中,我在root控制器中设置了childcontrollers的帧大小。子视图显示为我设置的大小,但是当我在container1中检查其边界时,它会报告与我设置的大小不同的大小。

I am implementing UIViewcontroller containment. In the example below I set the frame size of the childcontrollers in the rootcontroller. The child view appears as the size I have set, however when I check on its bounds within container1 it reports a different size to the size I set.

Rootcontroller(容器)

Rootcontroller (container)

- (void)viewDidLoad
{
  [super viewDidLoad];


self.containA = [[Container1 alloc]init];
self.containB = [[Container2 alloc]init];

 self.containA.view.frame = CGRectMake(50, 50,50, 50);
 self.containB.view.frame = CGRectMake(50, 50, 300, 300);

   [self addChildViewController:self.containA];
   [self addChildViewController:self.containB];

  [self.view addSubview:self.containA.view];

Container1

Container1

-(void)viewDidLoad {
    [super viewDidLoad];




UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//[self.view addSubview:view];
self.view = view;
self.view.backgroundColor = [UIColor redColor];
[view release];
 NSLog(@"view dims %f %f",self.view.bounds.size.width,self.view.bounds.size.height);
}

集装箱1的控制台输出
查看dims 768.000000 1004.000000

Console output from container 1 view dims 768.000000 1004.000000

我认为这个问题与将视图框设置为UIScreen主屏幕] applicationFrame有关。因此我删除了所有这些代码,以便自动创建uiview。问题仍然存在..

I thought the issue was related to setting the view frame to UIScreen main screen]applicationFrame .So I removed all of this code so the uiview is created automatically. The issue still remains..

推荐答案

查看框架在viewDidLoad中实际上不可用;您应该将所有几何操作代码移动到viewWillAppear中。系统会破坏你在viewDidLoad中设置的任何更改,以及当它关于tom进入屏幕时。

View frames are not actually useable in viewDidLoad; you should move all of your geometry-manipulating code into viewWillAppear. The system will clobber any changes you set in viewDidLoad between there and when it's about tom come on screen.

这篇关于在子控制器中查看控制器帧大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆