[英]swift 2.1 cannot convert value of type anyobject to expected argument type nslayoutconstraint
[英]Cannot convert value of type '[NSLayoutConstraint]' error in swift 2
使用addConstraints
而不是addConstraint
。 constraintsWithVisualFormat
返回一個數組。
您的代碼變為:
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[v0]|", options: [], metrics: nil, views: ["v0": userProfileImageView])
let horizontalprofileViewConstraint = NSLayoutConstraint.constraintsWithVisualFormat("H:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": userProfileImageView]
如果單擊選項並將鼠標懸停在horizontalprofileViewConstraint
您將看到其類型為[NSLayoutConstraint]
,它已經是一個數組。
因此,您可以做的是:
view.addConstraints(horizontalprofileViewConstraint)
如果您有多個視圖,則可以執行以下操作:
view.addConstraints(horizontalprofileViewConstraint + verticalprofileViewConstraint)
+
將為您加入數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.