尽管存在条件,但无法同时满足约束条件

Unable to simultaneously satisfy constraints despite of a condition

首先,我不使用故事板,我以编程方式在 UICollectionView 中设置我的元素。 根据我的 UICollectionView 中是否有项目,我在距顶部 16px 或 88px 的位置显示 UIView,为此,我使用了似乎不被尊重的 switch 条件.

我使用经典条件:

switch numberOfItems {
    case 0:
        print("nothing here")
        holderButtons.isHidden = true
        BottomView.anchor(top: bottomContainerView.topAnchor, leading: nil, bottom: nil, trailing: nil, padding: .init(top: 16, left: 0, bottom: 0, right: 0))
    default:
        print("1 or more")
        holderButtons.isHidden = false
        BottomView.anchor(top: bottomContainerView.topAnchor, leading: nil, bottom: nil, trailing: nil, padding: .init(top: 88, left: 0, bottom: 0, right: 0))
}

我也试过 if...else

该条件适用于隐藏视图,但不适用于我的 BottomView。 这是来自调试区的消息:

<NSLayoutConstraint:0x280f385a0 V:|-(16)-[UIView:0x1479337d0]   (active, names: '|':UIView:0x147933410 )>",
"<NSLayoutConstraint:0x280f13930 V:|-(88)-[UIView:0x1479337d0]   (active, names: '|':UIView:0x147933410 )>

我看不出有什么问题。 有什么想法吗?

好的,我终于将我的条件添加到 "setupElements" func 并且它工作正常:在我的调试区域中不再有 NSLayoutConstraint 错误。 即使当我滚动我的 UICollectionView 时我仍然遇到最初的问题:我有一个弹性 header 并且当我展开它直到我再也看不到我的单元格时,它 re-inits 我的情况......这是另一个问题:)