2015-08-28 51 views
0

我創建的auto layout constraintsIBOutlet值這裏的屏幕截圖IBOutlet中NSLayoutConstraint不給

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);的零寬度?

+3

只是一個提示,這樣可以節省您打印出rects時的一些輸入。您可以使用[NSValue valueWithCGRect:self.view.frame]來打印x,y,寬度和高度。 – Oblieapps

+3

甚至更​​好; NSStringFromCGRect(<#CGRect rect#>) –

+0

非常感謝你的提示:) –

回答

4

你會得到viewDidLayoutSubviews的值。

+0

但爲什麼我獲得高度值? –

+1

由於常數,這是一個固定的200.寬度與其他內容相關聯,一旦進入viewDidLayoutSubviews,就會進行計算。 –

+0

nope仍然零:( –