IBOutlet NSLayoutConstraint没有给出价值

时间:2015-08-28 07:53:16

标签: ios objective-c uiview autolayout nslayoutconstraint

我创建IBOutlet auto layout constraints这里是屏幕截图

enter image description here

enter image description here

enter image description here

这是代码

-(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.widthself.v.frame.size.height这样的帧属性是正确的还是我应该使用self.vWidth.constantself.vHeight.constant

问题2: 为什么我在NSLog(@"Constant=> w=%f, h=%f", self.vWidth.constant, self.vHeight.constant);中获得零宽度?

1 个答案:

答案 0 :(得分:4)

您将获得viewDidLayoutSubviews中的值。