【发布时间】:2013-07-15 15:07:55
【问题描述】:
我遇到了与here 相同的问题,即大型 UICollectionViewCell(显然是 UICollectionView 高度的两倍以上)在给定的滚动偏移量处消失,然后在给定的滚动偏移量后又重新出现。
我已经实现了@JonathanCichon solution,它是 UICollectionView 的子类,并在 _visibleBounds 上执行自定义操作(我知道这是一个私有 API,但没关系,我不需要在 Apple Store 上提交)
这是我的自定义收藏视图:
#import "CollectionView.h"
@interface UICollectionView ()
- (CGRect)_visibleBounds;
@end
@implementation CollectionView
- (CGRect)_visibleBounds
{
CGRect rect = [super _visibleBounds];
rect.size.height = [self heightOfLargestVisibleCell];
return rect;
}
- (CGFloat)heightOfLargestVisibleCell
{
// get current screen height depending on orientation
CGFloat screenSize = [self currentScreenHeight];
CGFloat largestCell = 0;
NSArray *visibleCells = self.visibleCells;
// get the largest height between visibleCells
for (UITableViewCell *c in visibleCells)
{
CGFloat h = c.frame.size.height;
largestCell = h > largestCell ? h : largestCell;
}
// return higher value between screen height and higher visible cell height
return MAX(largestCell, screenSize);
}
这有效,滚动时不再消失,但我仍然有一个问题:如果我在滚动位置位于大单元格中间时执行reloadData,它会像之前一样消失......
我注意到在重新加载数据后,visibleCells 返回nil(在我的heightOfLargestVisibleCell 方法中),所以我的屏幕高度为_visibleBounds 但由于屏幕高度
有人已经遇到过这个问题吗?
提前谢谢
【问题讨论】:
标签: ios uicollectionview uicollectionviewcell