这是代码,我创建了一个视图并将其添加到self(继承自MKMapView):
private func setup() {
coverView = UIView()
coverView.backgroundColor = UIColor.greenColor()
coverView.layer.zPosition = 10
addSubview(coverView)
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
"H:|[cover]|",
options: NSLayoutFormatOptions.allZeros,
metrics: nil,
views: ["cover": coverView]
) as! [NSLayoutConstraint])
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[cover]|",
options: NSLayoutFormatOptions.allZeros,
metrics: nil,
views: ["cover": coverView]
) as! [NSLayoutConstraint])
}
它说:
2015-09-07 14:53:59.234 ULine[48467:825531] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7fdd23320250 H:[UIView:0x7fdd2331f860]-(10)-| (Names: '|':ULine.ULineMap:0x7fdd20e25bc0 )>",
"<NSLayoutConstraint:0x7fdd232bb840 H:[ULine.ULineMap:0x7fdd20e25bc0]-(0)-| (Names: '|':UIView:0x7fdd23320910 )>",
"<NSLayoutConstraint:0x7fdd232bb890 H:|-(0)-[ULine.ULineMap:0x7fdd20e25bc0] (Names: '|':UIView:0x7fdd23320910 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7fdd232c0280 h=--& v=--& UIView:0x7fdd2331f860.midX ==>",
"<NSAutoresizingMaskLayoutConstraint:0x7fdd232c0af0 h=--& v=--& H:[UIView:0x7fdd2331f860(0)]>",
"<NSLayoutConstraint:0x7fdd237ee370 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fdd23320910(375)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fdd23320250 H:[UIView:0x7fdd2331f860]-(10)-| (Names: '|':ULine.ULineMap:0x7fdd20e25bc0 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
很奇怪,我只想让它填满整个视图。
谢谢
最佳答案
我在发布后解决了该问题,因为CoverView启用了“ TranslatesAutoresizingMaskIntoConstraints”,因此我只需添加coverView.setTranslatesAutoresizingMaskIntoConstraints(false)
,就不会再添加其他约束了。
希望对您有帮助。