2
我正在为一个专门的计算器界面上和我有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指出t他“容器”宽280px,高364px,所以出于某种原因,我没有得到正确的值。
我甚至试图找到super
的bounds
和frame
尺寸,但它们仍然是320x460。
有人可以告诉我我做错了什么吗?
在此先感谢
[更新]
只是为别人一些信息: 我已经做了一些测试类似的UI控件,并在这里是我的发现: (cvObject
是UICollectionView
对象)
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"%s: self.cvObject.bounds:\t%@", __FUNCTION__, NSStringFromCGRect(self.cvObject.bounds));
NSLog(@"%s: self.cvObject.frame:\t%@", __FUNCTION__, NSStringFromCGRect(self.cvObject.frame));
}
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"%s: self.cvObject.bounds:\t%@", __FUNCTION__, NSStringFromCGRect(self.cvObject.bounds));
NSLog(@"%s: self.cvObject.frame:\t%@", __FUNCTION__, NSStringFromCGRect(self.cvObject.frame));
}
- (void)viewDidAppear:(BOOL)animated
{
NSLog(@"%s: self.cvObject.bounds:\t%@", __FUNCTION__, NSStringFromCGRect(self.cvObject.bounds));
NSLog(@"%s: self.cvObject.frame:\t%@", __FUNCTION__, NSStringFromCGRect(self.cvObject.frame));
}
-(void)viewWillLayoutSubviews
{
NSLog(@"%s: self.cvObject.bounds:\t%@", __FUNCTION__, NSStringFromCGRect(self.cvObject.bounds));
NSLog(@"%s: self.cvObject.frame:\t%@", __FUNCTION__, NSStringFromCGRect(self.cvObject.frame));
}
-(void)viewDidLayoutSubviews
{
NSLog(@"%s: self.cvObject.bounds:\t%@", __FUNCTION__, NSStringFromCGRect(self.cvObject.bounds));
NSLog(@"%s: self.cvObject.frame:\t%@", __FUNCTION__, NSStringFromCGRect(self.cvObject.frame));
}
而我得到的是:
-[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}}
所以你可以看到,它只有在视图设置它的子视图之后,它才能确定对象的框架和边界。
谢谢!就是这样! – Darrell