gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:38:12 24 4
gpt4 key购买 nike

首先,我不使用 Storyboard,我以编程方式在 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

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

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

我不明白这有什么问题。有什么想法吗?

最佳答案

好吧,我终于将我的条件添加到了“setupElements”函数中,并且工作正常:在我的调试区域中不再出现 NSLayoutConstraint 错误。即使当我滚动 UICollectionView 时仍然遇到最初的问题:我有一个弹性标题,当我展开它直到我看不到我的单元格时,它会重新初始化我的条件...这是另一个问题:)

关于swift - 尽管存在条件,但无法同时满足约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57434692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com