iOS SnapKit和场景

时间:2015-12-05 14:08:24

标签: ios swift

我用一个场景制作了一个故事板。在我的UIViewController中,我使用SnapKit定义了以下内容:

@IBOutlet weak var emailTextField: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    emailTextField.snp_makeConstraints { (make) -> Void in
        make.size.equalTo(CGSizeMake(100, 40))
    }
}

我一直收到错误:

Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. 
Try this: 
    (1) look at each constraint and try to figure out which you don't expect; 
    (2) find the code that added the unwanted constraint or constraints and fix it. 

我已尝试过snp_remakeConstraintssnp_updateConstraints但错误相同。

我在这里做错了什么?

感谢。

1 个答案:

答案 0 :(得分:0)

发生问题,因为SnapKit仅删除了emailTextField自己的约束(通过自动设置translatesAutoresizingMaskIntoConstraints = false),因此仍然存在一些重复项。

对于情节提要约束,您需要清除所有默认约束。您可以使用以下代码来实现:

yourTextFieldsSuperviewName.removeConstraints(view.constraints)

祝你好运!