(编辑:从iOS 9开始看起来工作正常.我没有进行大量测试,但是这个例子很有效.这证实了iOS 8中存在的错误.)
我花了很多时间测试UICollectionView的Flow Layout自我调整大小的行为.经过很多挫折之后,问题被缩小到这样一个事实:只要将其设置为estimatedItemSize
非零大小,滚动就不再正常工作.
在我的示例中,它不显示40个项目,而只显示32个项目.
我复制粘贴下面的代码.我已经测试了许多以Swift版本开头的东西.
基本上它无法计算和/或正确更新布局 collectionViewContentSize()
这是一个完整的演示http://git.io/AIrHNA
有谁能指出我正确的方向?
谢谢
@implementation ViewControllerObjcC
static NSString * const reuseIdentifier = @"Cell";
-(UICollectionViewFlowLayout*)flowLayout{
return (UICollectionViewFlowLayout*)self.collectionViewLayout;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
CGSize estimatedSize = CGSizeMake(self.view.frame.size.width, 25.0);
BOOL testEstimatedItemSize = true;
if (testEstimatedItemSize) {
[self flowLayout].estimatedItemSize = estimatedSize;
}else{
[self flowLayout].itemSize = estimatedSize;
}
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 40;
}
- …
Run Code Online (Sandbox Code Playgroud) iphone objective-c ios uicollectionview uicollectionviewlayout