好吧,所以可以说我有UICollection 20个细胞与启用分页水平滚动和可容纳每一页上9个细胞,当我提出它,而不是10个细胞创建第二页面移动到足以适应页面上的第10个单元格。当我滚动时,我希望它在自己的页面上显示第10个单元格。UICollectionView不滚动完整320个分页启用
此外,我试图改变collectionview.contentsize但由于某种原因它保持相同的,无论我做什么。
这里是我的代码 -
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(82, 119);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(20, 10, 50, 10);
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
customCell *cell= (customCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
return (UICollectionViewCell*)cell;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 20;
}
- (void)viewDidLoad {
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
_collectionView=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout];
[_collectionView setDataSource:self];
[_collectionView setDelegate:self];
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
[_collectionView setBackgroundColor:[UIColor lightGrayColor]];
[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
_collectionView.pagingEnabled = YES;
layout.minimumInteritemSpacing = 15;
layout.minimumLineSpacing = 25;
[_collectionView setContentInset:UIEdgeInsetsMake(65, 0, 0, 0)];
_collectionView.allowsMultipleSelection = YES;
[self.view addSubview:_collectionView];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
这就是默认流程布局的工作方式。您可以增加单元格的大小,增加单元格之间的最小间距,和/或增加sectionInset。 – rdelmar 2014-12-13 01:01:15