用户在通话时不显示收集查看项目

RyJ*_*RyJ 3 ios uicollectionview

我有一个集合视图.当我切换通话中状态栏时,当您显示绿色的"您正在通话"状态栏时,我的收藏视图项目会消失.当我解雇酒吧时他们回来了.

日志吐出这个:"未定义UICollectionViewFlowLayout的行为,因为项目高度必须小于UICollectionView的高度减去该部分的顶部和底部值."

有没有人遇到过这个,你是如何得到它的?我使用sizeForItemAtIndexPath如下:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return self.collectionView.frame.size;
}
Run Code Online (Sandbox Code Playgroud)

我应该使用其他东西来指定每个项目的大小吗?

RyJ*_*RyJ 5

对于任何体验过此的人.这是定义项目大小的正确方法:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return self.collectionView.frame.size;
}
Run Code Online (Sandbox Code Playgroud)

您也可以在collectionViewLayout上设置itemSize,但是在电话调用时使项目保持不变并且不会消失的关键是在viewDidLayoutSubviews中重新加载集合视图:

[self.collectionView reloadData];
Run Code Online (Sandbox Code Playgroud)

  • 不是`self.collectionView.frame.size`返回*whole*view的大小? (2认同)