2016-08-09 60 views

Antwort

25

Verwenden Sie anstelle von addConstraint. constraintsWithVisualFormat gibt ein Array zurück.

Ihr Code wird:

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] 

Wenn Sie die Option klicken und den Mauszeiger über horizontalprofileViewConstraint Sie seinen Typ als [NSLayoutConstraint] sehen, die bereits ein Array ist.

Also, was können Sie tun, ist:

view.addConstraints(horizontalprofileViewConstraint) 

, wenn Sie mehr als eine Ansicht haben dann cand Sie tun:

view.addConstraints(horizontalprofileViewConstraint + verticalprofileViewConstraint) 

Die + schließt sich für Sie auf Arrays.