diff --git a/JNWCollectionView/JNWCollectionViewFramework.m b/JNWCollectionView/JNWCollectionViewFramework.m index 47ed56c..b8d4872 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.m +++ b/JNWCollectionView/JNWCollectionViewFramework.m @@ -99,9 +99,6 @@ static void JNWCollectionViewCommonInit(JNWCollectionView *collectionView) { // Set the document view to a custom class that returns YES to -isFlipped. collectionView.documentView = [[JNWCollectionViewDocumentView alloc] initWithFrame:CGRectZero]; - - collectionView.hasHorizontalScroller = NO; - collectionView.hasVerticalScroller = YES; // We don't want to perform an initial layout pass until the user has called -reloadData. collectionView->_collectionViewFlags.wantsLayout = NO; @@ -591,11 +588,31 @@ - (void)performFullRelayoutForcingSubviewsReset:(BOOL)forceReset { - (void)layoutDocumentView { if (!_collectionViewFlags.wantsLayout) return; + + [self updateScrollDirection]; NSView *documentView = self.documentView; documentView.frameSize = self.data.encompassingSize; } +- (void)updateScrollDirection { + switch (self.collectionViewLayout.scrollDirection) { + case JNWCollectionViewScrollDirectionVertical: + self.hasVerticalScroller = YES; + self.hasHorizontalScroller = NO; + break; + case JNWCollectionViewScrollDirectionHorizontal: + self.hasVerticalScroller = NO; + self.hasHorizontalScroller = YES; + break; + case JNWCollectionViewScrollDirectionBoth: + default: + self.hasVerticalScroller = YES; + self.hasHorizontalScroller = YES; + break; + } +} + - (CGSize)visibleSize { return self.documentVisibleRect.size; } diff --git a/JNWCollectionView/JNWCollectionViewLayout.h b/JNWCollectionView/JNWCollectionViewLayout.h index 752fefa..63b340c 100644 --- a/JNWCollectionView/JNWCollectionViewLayout.h +++ b/JNWCollectionView/JNWCollectionViewLayout.h @@ -27,6 +27,12 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewDirection) { JNWCollectionViewDirectionDown }; +typedef NS_ENUM(NSInteger, JNWCollectionViewScrollDirection) { + JNWCollectionViewScrollDirectionVertical, + JNWCollectionViewScrollDirectionHorizontal, + JNWCollectionViewScrollDirectionBoth +}; + @interface JNWCollectionViewLayoutAttributes : NSObject @property (nonatomic, assign) CGRect frame; @property (nonatomic, assign) CGFloat alpha; @@ -104,6 +110,18 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewDirection) { /// Defaults to CGSizeZero, which means it will fit the collection view's frame. - (CGSize)contentSize; +/// The scroll direction determines which way the collection view will show scroll indicators. +/// +/// Subclasses should override this method to change the scroll direction. +/// +/// Note that if the content view is larger than the bounds of the collection view, the content will +/// still be scrollable, even if the scroll indicators do not show up. To prevent this, do not make +/// the content view larger than the collection view itself in the direction in which you do not want +/// scrolling. +/// +/// Defaults to JNWCollectionViewScrollDirectionVertical. +- (JNWCollectionViewScrollDirection)scrollDirection; + /// Subclasses must implement this method for arrowed selection to work. - (NSIndexPath *)indexPathForNextItemInDirection:(JNWCollectionViewDirection)direction currentIndexPath:(NSIndexPath *)currentIndexPath; diff --git a/JNWCollectionView/JNWCollectionViewLayout.m b/JNWCollectionView/JNWCollectionViewLayout.m index 1fdf7e5..b390f41 100644 --- a/JNWCollectionView/JNWCollectionViewLayout.m +++ b/JNWCollectionView/JNWCollectionViewLayout.m @@ -60,6 +60,10 @@ - (CGSize)contentSize { return CGSizeZero; } +- (JNWCollectionViewScrollDirection)scrollDirection { + return JNWCollectionViewScrollDirectionVertical; +} + - (NSIndexPath *)indexPathForNextItemInDirection:(JNWCollectionViewDirection)direction currentIndexPath:(NSIndexPath *)currentIndexPath { return currentIndexPath; }