【发布时间】:2020-03-24 19:53:47
【问题描述】:
我有一个 CollectionView,我想根据内容动态调整它的高度。 我收到一个错误,因为情节提要中设置的约束与约束冲突 在我的代码中设置:
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(myCollectionView)
//other constraints of collectionView
collHeight = myCollectionView.heightAnchor.constraint(equalToConstant: 276)
collHeight!.isActive = true
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//other stuff
collHeight!.constant = collectionView.contentSize.height
view.layoutIfNeeded()
}
错误:https://pastebin.com/5yQh5hUP 我无法删除带有 Entf 的约束。 它只将数字设置为 0。我可以通过编程方式停用它吗?
【问题讨论】:
-
您认为这不值得关注吗? “如果您看到不理解的 NSAutoresizingMaskLayoutConstraints,请参阅 UIView 属性
translatesAutoresizingMaskIntoConstraints的文档。” -
另外你没有在
cellForItemAt中设置集合视图约束常量,这根本没有意义。
标签: ios swift xcode collectionview