我正在尝试布置一个彩色样本(只是一个 UIView 及其背景颜色设置),使其位于容器视图的左侧 . 它的容器的左侧,顶部和底部具有固定宽度( 10 )和固定距离( 8 ) . 这是它的样子:

enter image description here

样品是灰色的东西 . 其他内容当然会出现在右边,但我还没有达到那个目的 .

以下是我应用于swatch的约束:

enter image description here

但是,在运行时我得到了不可满足的约束:

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:0x15e53fe0 V:[UIView:0x15e57250]-(8)-|   (Names: '|':LogEntryView:0x15e57740 )>",
    "<NSLayoutConstraint:0x15e54010 V:|-(8)-[UIView:0x15e57250]   (Names: '|':LogEntryView:0x15e57740 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x15e528c0 h=-&- v=-&- LogEntryView:0x15e57740.height == LogEntryView:0x15e57150.height>",
    "<NSAutoresizingMaskLayoutConstraint:0x15e54f80 h=--& v=--& V:[LogEntryView:0x15e57150(0)]>"
)

做了一些阅读后,我怀疑是问题所在的_2835184 . 但是,我无法解决为什么他们检查每个视图以确保 translatesAutoresizingMaskIntoConstraintsNO ,而且确实如此 . 我使用了Interface Builder,无论如何都应该这样做 .

如果我删除了两个垂直约束,则不会显示错误 . 如果我只删除一个垂直约束(顶部或底部,无关紧要),则不会显示错误 .

谁能告诉我这里发生了什么?

UPDATE: 我意识到我的 LogEntryView 代码中有以下内容(我正在使用Xamarin):

public LogEntryView()
    {
        var arr = NSBundle.MainBundle.LoadNib("LogEntryView", this, null);
        var v = (UIView)Runtime.GetNSObject(arr.ValueAt(0));
        v.Frame = new RectangleF(0, 0, Frame.Width, Frame.Height);
        this.AddSubview(v);
    }

从NIB加载后直接检查 v.TranslatesAutoresizingMaskIntoConstraints 表明它是 true . 我不明白为什么,因为我认为NIB会将其存储为false,如界面构建器中所示 . 我将此代码更改为:

public LogEntryView()
    {
        this.TranslatesAutoresizingMaskIntoConstraints = false;
        var arr = NSBundle.MainBundle.LoadNib("LogEntryView", this, null);
        var v = (UIView)Runtime.GetNSObject(arr.ValueAt(0));
        v.TranslatesAutoresizingMaskIntoConstraints = false;
        this.AddSubview(v);
    }

现在错误没有出现,但我有一个不同的问题:样本现在根本没有出现 . 有任何想法吗?