Skip to content

Instantly share code, notes, and snippets.

@leeprobert
Created March 15, 2013 12:17
Show Gist options
  • Select an option

  • Save leeprobert/5169497 to your computer and use it in GitHub Desktop.

Select an option

Save leeprobert/5169497 to your computer and use it in GitHub Desktop.
UIcollectionViewFlowLayout class for changing the scroll direction based on device orientation.
//
// CollectionViewOrientingFlowLayout.m
// iP2
//
// Created by Lee Probert on 08/03/2013.
//
//
#define ITEM_SIZE 150.0f
#define PADDING 20
#import "CollectionViewOrientingFlowLayout.h"
@interface CollectionViewOrientingFlowLayout (){
UIInterfaceOrientation _orientation;
}
-(void)initLayoutProperties;
@end
@implementation CollectionViewOrientingFlowLayout
-(void)prepareLayout {
[super prepareLayout];
[self initLayoutProperties];
}
-(void)initLayoutProperties {
_orientation = [[UIApplication sharedApplication] statusBarOrientation];
self.itemSize = CGSizeMake(ITEM_SIZE, ITEM_SIZE);
self.scrollDirection = UIInterfaceOrientationIsPortrait(_orientation)? UICollectionViewScrollDirectionVertical : UICollectionViewScrollDirectionHorizontal;
self.minimumLineSpacing = PADDING;
self.minimumInteritemSpacing = PADDING;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment