PSTCollectionViewFlowLayout.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // PSTCollectionViewFlowLayout.h
  3. // PSPDFKit
  4. //
  5. // Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
  6. //
  7. #import "PSTCollectionViewLayout.h"
  8. extern NSString *const PSTCollectionElementKindSectionHeader;
  9. extern NSString *const PSTCollectionElementKindSectionFooter;
  10. typedef NS_ENUM(NSInteger, PSTCollectionViewScrollDirection) {
  11. PSTCollectionViewScrollDirectionVertical,
  12. PSTCollectionViewScrollDirectionHorizontal
  13. };
  14. @protocol PSTCollectionViewDelegateFlowLayout <PSTCollectionViewDelegate>
  15. @optional
  16. - (CGSize)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
  17. - (UIEdgeInsets)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;
  18. - (CGFloat)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section;
  19. - (CGFloat)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;
  20. - (CGSize)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;
  21. - (CGSize)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;
  22. @end
  23. @class PSTGridLayoutInfo;
  24. @interface PSTCollectionViewFlowLayout : PSTCollectionViewLayout
  25. @property (nonatomic) CGFloat minimumLineSpacing;
  26. @property (nonatomic) CGFloat minimumInteritemSpacing;
  27. @property (nonatomic) CGSize itemSize; // for the cases the delegate method is not implemented
  28. @property (nonatomic) PSTCollectionViewScrollDirection scrollDirection; // default is PSTCollectionViewScrollDirectionVertical
  29. @property (nonatomic) CGSize headerReferenceSize;
  30. @property (nonatomic) CGSize footerReferenceSize;
  31. @property (nonatomic) UIEdgeInsets sectionInset;
  32. /*
  33. Row alignment options exits in the official UICollectionView, but hasn't been made public API.
  34. Here's a snippet to test this on UICollectionView:
  35. NSMutableDictionary *rowAlign = [[flowLayout valueForKey:@"_rowAlignmentsOptionsDictionary"] mutableCopy];
  36. rowAlign[@"UIFlowLayoutCommonRowHorizontalAlignmentKey"] = @(1);
  37. rowAlign[@"UIFlowLayoutLastRowHorizontalAlignmentKey"] = @(3);
  38. [flowLayout setValue:rowAlign forKey:@"_rowAlignmentsOptionsDictionary"];
  39. */
  40. @property (nonatomic, strong) NSDictionary *rowAlignmentOptions;
  41. @end
  42. // @steipete addition, private API in UICollectionViewFlowLayout
  43. extern NSString *const PSTFlowLayoutCommonRowHorizontalAlignmentKey;
  44. extern NSString *const PSTFlowLayoutLastRowHorizontalAlignmentKey;
  45. extern NSString *const PSTFlowLayoutRowVerticalAlignmentKey;
  46. typedef NS_ENUM(NSInteger, PSTFlowLayoutHorizontalAlignment) {
  47. PSTFlowLayoutHorizontalAlignmentLeft,
  48. PSTFlowLayoutHorizontalAlignmentCentered,
  49. PSTFlowLayoutHorizontalAlignmentRight,
  50. PSTFlowLayoutHorizontalAlignmentJustify // 3; default except for the last row
  51. };
  52. // TODO: settings for UIFlowLayoutRowVerticalAlignmentKey
  53. /*
  54. @interface PSTCollectionViewFlowLayout (Private)
  55. - (CGSize)synchronizeLayout;
  56. // For items being inserted or deleted, the collection view calls some different methods, which you should override to provide the appropriate layout information.
  57. - (PSTCollectionViewLayoutAttributes *)initialLayoutAttributesForFooterInInsertedSection:(NSInteger)section;
  58. - (PSTCollectionViewLayoutAttributes *)initialLayoutAttributesForHeaderInInsertedSection:(NSInteger)section;
  59. - (PSTCollectionViewLayoutAttributes *)initialLayoutAttributesForInsertedItemAtIndexPath:(NSIndexPath *)indexPath;
  60. - (PSTCollectionViewLayoutAttributes *)finalLayoutAttributesForFooterInDeletedSection:(NSInteger)section;
  61. - (PSTCollectionViewLayoutAttributes *)finalLayoutAttributesForHeaderInDeletedSection:(NSInteger)section;
  62. - (PSTCollectionViewLayoutAttributes *)finalLayoutAttributesForDeletedItemAtIndexPath:(NSIndexPath *)indexPath;
  63. - (void)_updateItemsLayout;
  64. - (void)_getSizingInfos;
  65. - (void)_updateDelegateFlags;
  66. - (PSTCollectionViewLayoutAttributes *)layoutAttributesForFooterInSection:(NSInteger)section;
  67. - (PSTCollectionViewLayoutAttributes *)layoutAttributesForHeaderInSection:(NSInteger)section;
  68. - (PSTCollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath usingData:(id)data;
  69. - (PSTCollectionViewLayoutAttributes *)layoutAttributesForFooterInSection:(NSInteger)section usingData:(id)data;
  70. - (PSTCollectionViewLayoutAttributes *)layoutAttributesForHeaderInSection:(NSInteger)section usingData:(id)data;
  71. - (id)indexesForSectionFootersInRect:(CGRect)rect;
  72. - (id)indexesForSectionHeadersInRect:(CGRect)rect;
  73. - (id)indexPathsForItemsInRect:(CGRect)rect usingData:(id)arg2;
  74. - (id)indexesForSectionFootersInRect:(CGRect)rect usingData:(id)arg2;
  75. - (id)indexesForSectionHeadersInRect:(CGRect)arg1 usingData:(id)arg2;
  76. - (CGRect)_frameForItemAtSection:(int)arg1 andRow:(int)arg2 usingData:(id)arg3;
  77. - (CGRect)_frameForFooterInSection:(int)arg1 usingData:(id)arg2;
  78. - (CGRect)_frameForHeaderInSection:(int)arg1 usingData:(id)arg2;
  79. - (void)_invalidateLayout;
  80. - (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)arg1;
  81. - (PSTCollectionViewLayoutAttributes *)_layoutAttributesForItemsInRect:(CGRect)arg1;
  82. - (CGSize)collectionViewContentSize;
  83. - (void)finalizeCollectionViewUpdates;
  84. - (void)_invalidateButKeepDelegateInfo;
  85. - (void)_invalidateButKeepAllInfo;
  86. - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)arg1;
  87. - (id)layoutAttributesForElementsInRect:(CGRect)arg1;
  88. - (void)invalidateLayout;
  89. - (id)layoutAttributesForItemAtIndexPath:(id)arg1;
  90. @end
  91. */