は2

2016-08-09 4 views
9

迅速に、私はこのコード行を追加することでUIImageViewに制約を追加したいタイプ「[NSLayoutConstraint]」エラーの値は変換できませんは2

enter image description here

どうすればこのエラーを修正できますか?

答えて

25

addConstraintの代わりにを使用してください。 constraintsWithVisualFormatは配列を返します。

あなたのコードは次のようになります。

addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[v0]|", options: [], metrics: nil, views: ["v0": userProfileImageView]) 
2
let horizontalprofileViewConstraint = NSLayoutConstraint.constraintsWithVisualFormat("H:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": userProfileImageView] 

すでに配列です[NSLayoutConstraint]としてのタイプが表示されますhorizontalprofileViewConstraint上でオプションをクリックして置くと。

だから、何を行うことができますことは次のとおりです。

view.addConstraints(horizontalprofileViewConstraint) 

あなたが複数のビューを持っているならば、あなたはCAND:

​​

+はあなたのためのアレイに参加します。