【发布时间】:2014-04-18 21:58:52
【问题描述】:
展示我的问题的最佳方式是使用下面的视频:
http://foffer.dk/collectionview.mp4
如您所见,在开始滚动之前,我的 collectionView 不会更新其布局以正确显示项目。我正在使用单独的 collectionViewFlowLayout 模型。这是我的代码:
CollectionViewFlowLayout.m:
@implementation CollectionViewFlowLayout
- (void)prepareLayout {
CGFloat halfWidth = self.collectionView.bounds.size.width / 2;
CGFloat halfHeight = self.collectionView.bounds.size.height / 2;
self.itemSize = CGSizeMake(halfWidth, halfHeight);
self.minimumInteritemSpacing = 0;
self.minimumLineSpacing = 0;
}
// indicate that we want to redraw as we scroll
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
return YES;
}
@end
我的 PhotosCollectionViewController(我忽略了标准 collectionView 的东西,因为我认为这对这个问题并不重要,如果是,请告诉我,我会发布它):
-(instancetype)init {
UICollectionViewFlowLayout *layout = [[CollectionViewFlowLayout alloc] init];
return (self = [super initWithCollectionViewLayout:layout]);
}
-(void) viewDidLoad{
[super viewDidLoad];
[self.collectionView registerClass:[FOFPhotoCell class] forCellWithReuseIdentifier:@"photo"];
self.collectionView.backgroundColor = [UIColor whiteColor];
CGFloat bottomLayoutGuide = self.tabBarController.tabBar.frame.size.height;
self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, bottomLayoutGuide, 0);
}
-(BOOL)shouldAutorotate{
return YES;
}
我需要在某处调用 invalidateLayout 吗?我似乎无法弄清楚在哪里实现该方法。 [self.collectionView invalidateLayout] 不起作用。
有人能让我走上正确的道路吗?
提前致谢 克里斯
【问题讨论】:
标签: ios uicollectionview uicollectionviewlayout