As others have already said, the UICollectionView
can only scroll one direction using a flow layout. However you can accomplish this very easily without creating a custom layout or using a third party library.
When you lay your view out in story board, you can put your UICollectionView
embedded in a UIScrollView
. Have the scrollview set up to scroll horizontally and the UICollectionView
to scroll Vertically. Then set the UICollectionView.delaysContentTouches
to true so touches will pass through to the UIScrollView
and not think you are trying to scroll the collectionview.
When you set up the UICollectionView
, set it's size and the size of the cells to be what you actually want them to be (Wider than the actual screen) and lay them out accordingly.
Now in the containing UIViewController
put this code in the view lifecycle
- (void)viewDidLayoutSubviews {
self.myScrollView.contentSize = self.myCollectionView.frame.size;
}
That's literally all you have to do to accomplish what you are describing. Now your scrollview should allow you to scroll horizontally to view your entire cell and your collectionView should scroll vertically through your cells.
Happy programming.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…