2014-02-18 50 views
1

我在storyboard的ViewController視圖(父視圖)中放置了UIView(子視圖)。
我正在使用AutoLayout。
當我運行iPhone3.5" 設備上的應用程序,父視圖的高度是480,但子視圖的身高是568 我怎樣才能設置子視圖的高度一樣使用AutoLayoutiPhone如何使用自動佈局使子視圖高度與父視圖高度相同

家長的高度關注中是什麼我嘗試過,但沒有效果。

1)在故事板 「高度相等」 約束被禁用。
2)我把代碼中的ViewController的viewDidLoad

NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:myView 
                   attribute:NSLayoutAttributeHeight 
                   relatedBy:NSLayoutRelationEqual 
                   toItem:self.view 
                   attribute:NSLayoutAttributeHeight 
                  multiplier:1.0 
                   constant:0]; 
[self.view addConstraint:constraint]; 

回答

0

您需要附加的頂部,底部,導致與常數0後,乘數1

的屬性將是需要設置如下:

NSLayoutAttributeTop, 
    NSLayoutAttributeBottom, 
    NSLayoutAttributeLeading, 
    NSLayoutAttributeTrailing 

這種方法的方法是:

constraintWithItem:屬性:relatedBy:toItem:屬性:乘數:常數:


這樣做會使用視覺約束如下與垂直以下視覺格式的另一種方法:

五:[yourView]

和用於水平以下:

H:[yourView]

注1:此方法使用的方法是

constraintsWithVisualFormat:options:metrics:views: 

注2:不具有「-」旁邊這意味着在上海華的距離爲0


而且做起來會用故事板的最後方式。所有你需要做的是設置視圖內的方法1約束關於其超視圖,並且具有恆定的0.

我希望它有幫助。

+0

我試圖使用故事板和代碼添加4個約束,但子視圖的高度總是568在iPhone3.5「device。 – imfromMO

+0

什麼是您的父視圖?是否可能是滾動視圖? –

+0

父視圖和子視圖是UIView – imfromMO

相關問題