gpt4 book ai didi

ios - 如何调整调整 UICollectionView 大小的 Autolayout 位置?

转载 作者:行者123 更新时间:2023-11-29 01:15:38 25 4
gpt4 key购买 nike

我有以下设置,其中位于两个标题之间的 UICollectionView 调整大小以适合其所有单元格。它基本上是表格格式的 2x2 布局。

enter image description here

现在,加载数据后,我使用以下命令来调整 UICollectionView 的大小。

- (void)loadContent {

[self.collectionViewAboutProperty reloadData];

[self.labelAddress setText:stringAddress];

float totRows = [self.dictAboutProperty count];

float cHeight = ceil(totRows/2.0);

float collectionHeight = (cHeight * 20) + (cHeight * 5);

[self.collectionViewAboutProperty setFrame:CGRectMake(self.collectionViewAboutProperty.frame.origin.x, self.collectionViewAboutProperty.frame.origin.y, self.collectionViewAboutProperty.frame.size.width, collectionHeight)];

}

问题是,当发生上述情况时,它会与底部标题重叠。几乎就像底部标题上的自动布局约束被完全忽略一样。目前,我已将其设置为距上面 UICollectionView

约 25 像素的空间

如何才能在加载内容并且动态调整 Collection View 大小时,下面的 View 自行更新以满足约束?

谢谢

最佳答案

[self.labelAddress setText:stringAddress];

float totRows = [self.dictAboutProperty count];

float cHeight = ceil(totRows/2.0);

float collectionHeight = (cHeight * 20) + (cHeight * 5);

[self.collectionViewAboutProperty setFrame:CGRectMake(self.collectionViewAboutProperty.frame.origin.x, self.collectionViewAboutProperty.frame.origin.y, self.collectionViewAboutProperty.frame.size.width, collectionHeight)];
[self.collectionViewAboutProperty reloadData];

将解决您的问题。

关于ios - 如何调整调整 UICollectionView 大小的 Autolayout 位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35222063/

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