ios6中的Autolayout

问题描述:

我正在测试添加自动布局约束以编程方式查看。但它隐藏了我的观点。我正在写代码...ios6中的Autolayout

UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(50.0, 200.0, 600.0, 200.0)]; 
[testView setBackgroundColor:[UIColor grayColor]]; 

[self.view addSubview:testView]; 

[testView setTranslatesAutoresizingMaskIntoConstraints:NO]; 

NSDictionary *views = NSDictionaryOfVariableBindings(testView); 

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[testView(>=600)]-50-|" options:0 metrics:nil views:views]]; 

为什么这个隐藏我的看法? 请帮帮我。谢谢。

你还没有给出它在垂直方向上的任何约束,所以0点的高度满足你给它的所有约束。如果你愿意,Autolayout喜欢跳到0。