Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 视图控制器';s视图';s属性_Ios_View_Uiviewcontroller_Frame_Bounds - Fatal编程技术网

Ios 视图控制器';s视图';s属性

Ios 视图控制器';s视图';s属性,ios,view,uiviewcontroller,frame,bounds,Ios,View,Uiviewcontroller,Frame,Bounds,我正在为一个专用计算器开发接口,在IB中有以下设置: 我使用了IB中的“容器视图”,并将其设置为与我的自定义视图控制器“ButtonViewController”相等 然后,在ButtonViewController.m文件中,我有以下内容: - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor colorWithRed: 0.75 green: 0.0 blue: 0.

我正在为一个专用计算器开发接口,在IB中有以下设置:

我使用了IB中的“容器视图”,并将其设置为与我的自定义视图控制器“ButtonViewController”相等

然后,在ButtonViewController.m文件中,我有以下内容:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithRed: 0.75 green: 0.0 blue: 0.0 alpha: 1.0 ];
    NSLog(@"self.view.bounds.size.width:\t%f", self.view.bounds.size.width);
    NSLog(@"self.view.bounds.size.height:\t%f", self.view.bounds.size.height);

    NSLog(@"self.view.frame.size.width:\t%f", self.view.frame.size.width);
    NSLog(@"self.view.frame.size.height:\t%f", self.view.frame.size.height);
}
我得到以下屏幕输出:

和以下控制台输出:

self.view.bounds.size.width:    320.000000
self.view.bounds.size.height:   460.000000
self.view.frame.size.width:     320.000000
self.view.frame.size.height:    460.000000
Interface Builder声明“容器”的宽度为280px,高度为364px,因此出于某种原因,我没有得到正确的值

我甚至试图找到
super
bounds
frame
维度,但结果仍然是320x460

有人能告诉我我做错了什么吗

提前谢谢

[更新]

只是为其他人提供一些信息: 我使用类似的UI控件进行了一些测试,我发现: (
cvObject
是一个
UICollectionView
对象)

我得到的是:

-[FPViewController viewDidLoad]: self.cvObject.bounds:  {{0, 0}, {0, 0}}
-[FPViewController viewDidLoad]: self.cvObject.frame:   {{0, 0}, {0, 0}}
-[FPViewController viewWillAppear:]: self.cvObject.bounds:  {{0, 0}, {0, 0}}
-[FPViewController viewWillAppear:]: self.cvObject.frame:   {{0, 0}, {0, 0}}
-[FPViewController viewWillLayoutSubviews]: self.cvObject.bounds:   {{0, 0}, {0, 0}}
-[FPViewController viewWillLayoutSubviews]: self.cvObject.frame:    {{0, 0}, {0, 0}}
-[FPViewController viewDidLayoutSubviews]: self.cvObject.bounds:    {{0, 0}, {280, 312}}
-[FPViewController viewDidLayoutSubviews]: self.cvObject.frame: {{20, 128}, {280, 312}}
-[FPViewController viewDidAppear:]: self.cvObject.bounds:   {{0, 0}, {280, 312}}
-[FPViewController viewDidAppear:]: self.cvObject.frame:    {{20, 128}, {280, 312}}

因此,您可以看到,只有在视图布局其子视图之后,它才能确定对象的帧和边界。

您应该在
视图中重新检查这些值,然后您会发现在那里可以看到正确的值:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithRed: 0.75 green: 0.0 blue: 0.0 alpha: 1.0 ];

    // frame and bounds are not entirely reliable at this point

    NSLog(@"%s: self.view.bounds:\t%@", __FUNCTION__, NSStringFromCGRect(self.view.bounds));
    NSLog(@"%s: self.view.frame:\t%@", __FUNCTION__, NSStringFromCGRect(self.view.frame));
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // frame and bounds have generally been updated correctly by this point

    NSLog(@"%s: self.view.bounds:\t%@", __FUNCTION__, NSStringFromCGRect(self.view.bounds));
    NSLog(@"%s: self.view.frame:\t%@", __FUNCTION__, NSStringFromCGRect(self.view.frame));
}
- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithRed: 0.75 green: 0.0 blue: 0.0 alpha: 1.0 ];

    // frame and bounds are not entirely reliable at this point

    NSLog(@"%s: self.view.bounds:\t%@", __FUNCTION__, NSStringFromCGRect(self.view.bounds));
    NSLog(@"%s: self.view.frame:\t%@", __FUNCTION__, NSStringFromCGRect(self.view.frame));
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // frame and bounds have generally been updated correctly by this point

    NSLog(@"%s: self.view.bounds:\t%@", __FUNCTION__, NSStringFromCGRect(self.view.bounds));
    NSLog(@"%s: self.view.frame:\t%@", __FUNCTION__, NSStringFromCGRect(self.view.frame));
}