我收到了错误:
Invalid parameter not satisfying: [constraint isKindOfClass:[NSLayoutConstraint class]]
let d:NSDictionary = ["scrollView": scrollView] let hc:NSArray = [NSLayoutConstraint.constraintsWithVisualFormat("H:|[scrollView]|",options: NSLayoutFormatOptions.allZeros,metrics: nil,views: d)] let vc:NSArray = [NSLayoutConstraint.constraintsWithVisualFormat("V:|[scrollView]|",views: d)] view.addConstraints(hc) view.addConstraints(vc)
有谁知道这个错误试图告诉我什么?据我所知,参数是NSArray类型,其中包含NSLayoutConstraint对象.我怀疑我必须明确地将数组定义为NSArray,但这并没有解决它.
解决方法
NSLayoutConstraint.constraintsWithVisualFormat已经返回一个NSArray,因此您不需要将其包装在另一个数组中.所以尝试:
let d:NSDictionary = ["scrollView": scrollView] let hc:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("H:|[scrollView]|",views: d) let vc:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("V:|[scrollView]|",views: d) view.addConstraints(hc) view.addConstraints(vc)