我创建IBOutlet
auto layout constraints
这里是屏幕截图
这是代码
-(void)viewDidAppear:(BOOL)animated {
NSLog(@"View=> x=%f, y=%f, w=%f, h=%f", self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width ,self.view.frame.size.height);
NSLog(@"V=> x=%f, y=%f, w=%f, h=%f", self.v.frame.origin.x, self.v.frame.origin.y, self.v.frame.size.width ,self.v.frame.size.height);
NSLog(@"Constant=> w=%f, h=%f", self.vWidth.constant, self.vHeight.constant);
}
这是输出
View=> x=0.000000, y=0.000000, w=414.000000, h=736.000000
V=> x=0.000000, y=536.000000, w=414.000000, h=200.000000
Constant=> w=0.000000, h=200.000000
问题1:
使用auto layouts
时,获取像self.v.frame.size.width
,self.v.frame.size.height
这样的帧属性是正确的还是我应该使用self.vWidth.constant
,self.vHeight.constant
?
问题2:
为什么我在NSLog(@"Constant=> w=%f, h=%f", self.vWidth.constant, self.vHeight.constant);
中获得零宽度?
答案 0 :(得分:4)
您将获得viewDidLayoutSubviews
中的值。