当我以编程方式添加约束时,为什么约束不起作用?

时间:2016-01-03 01:49:16

标签: ios swift constraints

我有这样的观点:

enter image description here

当我执行特定操作时,我想显示一个视图。这些是我的约束:

    self.view.addSubview(messageView)
    let leftConstraint = messageView.leftAnchor.constraintEqualToAnchor(self.myTableView.leftAnchor)
    let bottomConstraint = messageView.bottomAnchor.constraintEqualToAnchor(self.myTableView.bottomAnchor)
    let highConstratin = messageView.heightAnchor.constraintEqualToConstant(44.0)
    let widthConstraint = messageView.widthAnchor.constraintEqualToAnchor(self.myTableView.widthAnchor)
    NSLayoutConstraint.activateConstraints([leftConstraint, bottomConstraint, highConstratin, widthConstraint])
    self.view.translatesAutoresizingMaskIntoConstraints = false
self.view.setNeedsDisplay()

但问题是视图只是在左上角添加,就像约束不起作用一样,

请看

enter image description here

我想念的是什么?

0 个答案:

没有答案