为什么不能为故事板中创建的UIView添加约束?

时间:2014-11-04 17:37:47

标签: autolayout constraints

我尝试为UIview添加约束,这是IBOutlet属性,但似乎不起作用。我还将TranslatesAutoresizingMaskIntoConstraints设置为no。

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.\

[_view1 setTranslatesAutoresizingMaskIntoConstraints:NO];
NSDictionary *views = NSDictionaryOfVariableBindings(_view1);

[self.view addConstraints:
 [NSLayoutConstraint constraintsWithVisualFormat:@"V:[_view1(40)]-30-|"
                                         options:0
                                         metrics:nil
                                           views:views]];

[self.view addConstraints:
 [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_view1(30)]"
                                         options:0
                                         metrics:nil
                                           views:views]];

}

我应该怎么做才能纠正它?

1 个答案:

答案 0 :(得分:0)

如果此视图在storyboard中有任何约束,则需要在其他约束之前删除视图约束...