0

这是代码,我创建了一个视图并将其添加到 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.

很奇怪,我只是想让它填满超级视图。谢谢

4

1 回答 1

0

我发布后解决了它,因为coverView启用了“TranslatesAutoresizingMaskIntoConstraints”,我只是简单地添加coverView.setTranslatesAutoresizingMaskIntoConstraints(false),没有添加额外的约束。

希望它可以帮助你。

于 2015-09-07T07:09:21.510 回答