Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the scroll direction in UICollectionView?

I have a UICollectionView in my storyboard based iOS app. When the device is in the portrait orientation I'd like it to scroll vertically, and when it's in Landscaper I'd like it to scroll horizontally.

In UICollectionView I can see the scrollEnabled member, but I can see no way to set the scroll direction. Have I missed something?

like image 410
Kenny Avatar asked Aug 27 '13 11:08

Kenny


2 Answers

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; 

Note too that it seems to be fine to call this in prepareForLayout in your flow layout...

@interface LayoutHorizontalThings : UICollectionViewFlowLayout @end  @implementation LayoutHorizontalBooks -(void)prepareLayout     {     [super prepareLayout];      self.scrollDirection = UICollectionViewScrollDirectionHorizontal;      self.minimumInteritemSpacing = 0;     self.minimumLineSpacing = 0;     self.itemSize = CGSizeMake(110,130);     self.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);     } 
like image 187
user3040186 Avatar answered Sep 18 '22 12:09

user3040186


Set the scrollDirection of the collection view's collectionViewLayout.

Docs are here.

like image 39
Mundi Avatar answered Sep 18 '22 12:09

Mundi