UICollectionView-水平排列单元格 [英] UICollectionView - order cells horizontally
本文介绍了UICollectionView-水平排列单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以基本上我的问题是我的uicollectionview的单元是从上到下而不是从左到右排序的.
So basically my problem is that my uicollectionview's cells are ordered from top to bottom, rather than from left to right.
This is what it looks like -
[1][4][7]
[2][5][8]
[3][6][9]
This is what i want -
[1][2][3]
[4][5][6]
[7][8][9]
另一个问题是,当我水平滚动而不是将页面移动整整320点时.它只能移动到足以容纳视图中下一个单元格的位置.
Another problem is when i scroll horizontally instead of moving the page a full 320points. It only moves enough to fit the next cell in the view.
this is what it looks like -
[2][3][10]
[5][6][ ]
[8][9][ ]
this is what i want -
[10][ ][ ]
[ ][ ][ ]
[ ][ ][ ]
我希望水平渲染可以解决它.我对ios还是陌生的,所以请告诉我如何做,我搜索的所有tut都不是我的确切问题或已过时.
I was hoping rendering it horizontally would fix it though. I'm still new to ios so please show me how to do it, all the tuts i searched are not for my exact problem or is outdated.
推荐答案
这是我的解决方案,希望对您有所帮助:
This is my solution, hope it helpful:
CELLS_PER_ROW = 4;
CELLS_PER_COLUMN = 5;
CELLS_PER_PAGE = CELLS_PER_ROW * CELLS_PER_COLUMN;
UICollectionViewFlowLayout* flowLayout = (UICollectionViewFlowLayout*)collectionView.collectionViewLayout;
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flowLayout.itemSize = new CGSize (size.width / CELLS_PER_ROW - delta, size.height / CELLS_PER_COLUMN - delta);
flowLayout.minimumInteritemSpacing = ..;
flowLayout.minimumLineSpacing = ..;
..
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger index = indexPath.row;
NSInteger page = index / CELLS_PER_PAGE;
NSInteger indexInPage = index - page * CELLS_PER_PAGE;
NSInteger row = indexInPage % CELLS_PER_COLUMN;
NSInteger column = indexInPage / CELLS_PER_COLUMN;
NSInteger dataIndex = row * CELLS_PER_ROW + column + page * CELLS_PER_PAGE;
id cellData = _data[dataIndex];
...
}
这篇关于UICollectionView-水平排列单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文