gpt4 book ai didi

ios - 获取 UIScrollView 内的 UICollectionView 高度

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

我在 ScrollView 中有一个 UICollectionView,它具有动态宽度和静态高度的单元格。

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return tagArray.count;

}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

TagsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"tagsCollectionViewCell" forIndexPath:indexPath ];
[cell bindWithModel:tagArray[indexPath.row]];

return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize yourLabelSize = [tagArray[indexPath.row] sizeWithAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:17.0f]}];

return CGSizeMake(yourLabelSize.width+20+40, 40);

}

我可以使用以下方法计算高度:

CGFloat height = self.collectionView.collectionViewLayout.collectionViewContentSize.height;

enter image description here我得到的值比实际高度高。

最佳答案

collectionView:layout:sizeForItemAtIndexPath:

向代理询问指定项的单元格的大小。

CGFloat height = self.collectionView.collectionViewLayout.collectionViewContentSize.height

这将返回 collectionView 高度而不是 collectionView Cell 的高度。

关于ios - 获取 UIScrollView 内的 UICollectionView 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45571515/

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