Created
March 15, 2013 12:17
-
-
Save leeprobert/5169497 to your computer and use it in GitHub Desktop.
UIcollectionViewFlowLayout class for changing the scroll direction based on device orientation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // 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