Skip to content

Commit

Permalink
Add new abilities
Browse files Browse the repository at this point in the history
  • Loading branch information
System Administrator authored and System Administrator committed Jan 21, 2017
1 parent 418974c commit 244cef6
Show file tree
Hide file tree
Showing 3 changed files with 859 additions and 6 deletions.
12 changes: 6 additions & 6 deletions taskCollectionWaterfall.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
7EAF20F11E3056990076B7EA /* FSServerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EAF20F01E3056990076B7EA /* FSServerManager.m */; };
7EAF20F41E3058DD0076B7EA /* FSUser.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EAF20F31E3058DD0076B7EA /* FSUser.m */; };
7EAF20F71E305EC20076B7EA /* FSCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EAF20F61E305EC20076B7EA /* FSCollectionViewCell.m */; };
7EAF20FD1E329CB30076B7EA /* CHTCollectionViewWaterfallLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EAF20FC1E329CB20076B7EA /* CHTCollectionViewWaterfallLayout.m */; };
7EAF21031E340ABD0076B7EA /* CHTCollectionViewWaterfallLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EAF21021E340ABD0076B7EA /* CHTCollectionViewWaterfallLayout.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -109,8 +109,8 @@
7EAF20F31E3058DD0076B7EA /* FSUser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSUser.m; sourceTree = "<group>"; };
7EAF20F51E305EC20076B7EA /* FSCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCollectionViewCell.h; sourceTree = "<group>"; };
7EAF20F61E305EC20076B7EA /* FSCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCollectionViewCell.m; sourceTree = "<group>"; };
7EAF20FB1E329CB20076B7EA /* CHTCollectionViewWaterfallLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CHTCollectionViewWaterfallLayout.h; path = "../../../../../../Downloads/CHTCollectionViewWaterfallLayout-develop/CHTCollectionViewWaterfallLayout.h"; sourceTree = "<group>"; };
7EAF20FC1E329CB20076B7EA /* CHTCollectionViewWaterfallLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CHTCollectionViewWaterfallLayout.m; path = "../../../../../../Downloads/CHTCollectionViewWaterfallLayout-develop/CHTCollectionViewWaterfallLayout.m"; sourceTree = "<group>"; };
7EAF21011E340ABD0076B7EA /* CHTCollectionViewWaterfallLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHTCollectionViewWaterfallLayout.h; sourceTree = "<group>"; };
7EAF21021E340ABD0076B7EA /* CHTCollectionViewWaterfallLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHTCollectionViewWaterfallLayout.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -210,8 +210,8 @@
7EAF20BC1E3056210076B7EA /* Libs */ = {
isa = PBXGroup;
children = (
7EAF20FB1E329CB20076B7EA /* CHTCollectionViewWaterfallLayout.h */,
7EAF20FC1E329CB20076B7EA /* CHTCollectionViewWaterfallLayout.m */,
7EAF21011E340ABD0076B7EA /* CHTCollectionViewWaterfallLayout.h */,
7EAF21021E340ABD0076B7EA /* CHTCollectionViewWaterfallLayout.m */,
7EAF20BD1E3056210076B7EA /* AFNetworking */,
7EAF20CB1E3056210076B7EA /* UIKit+AFNetworking */,
);
Expand Down Expand Up @@ -410,7 +410,7 @@
7EAF20881E3051760076B7EA /* main.m in Sources */,
7EAF20E11E3056210076B7EA /* AFNetworkReachabilityManager.m in Sources */,
7EAF20F71E305EC20076B7EA /* FSCollectionViewCell.m in Sources */,
7EAF20FD1E329CB30076B7EA /* CHTCollectionViewWaterfallLayout.m in Sources */,
7EAF21031E340ABD0076B7EA /* CHTCollectionViewWaterfallLayout.m in Sources */,
7EAF20ED1E3056210076B7EA /* UIRefreshControl+AFNetworking.m in Sources */,
7EAF20BB1E30527C0076B7EA /* FSCollectionViewController.m in Sources */,
7EAF20E61E3056210076B7EA /* AFAutoPurgingImageCache.m in Sources */,
Expand Down
325 changes: 325 additions & 0 deletions taskCollectionWaterfall/Libs/CHTCollectionViewWaterfallLayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
//
// UICollectionViewWaterfallLayout.h
//
// Created by Nelson on 12/11/19.
// Copyright (c) 2012 Nelson Tai. All rights reserved.
//

#import <UIKit/UIKit.h>

/**
* Enumerated structure to define direction in which items can be rendered.
*/
typedef NS_ENUM (NSUInteger, CHTCollectionViewWaterfallLayoutItemRenderDirection) {
CHTCollectionViewWaterfallLayoutItemRenderDirectionShortestFirst,
CHTCollectionViewWaterfallLayoutItemRenderDirectionLeftToRight,
CHTCollectionViewWaterfallLayoutItemRenderDirectionRightToLeft
};

/**
* Constants that specify the types of supplementary views that can be presented using a waterfall layout.
*/

/// A supplementary view that identifies the header for a given section.
extern NSString *const CHTCollectionElementKindSectionHeader;
/// A supplementary view that identifies the footer for a given section.
extern NSString *const CHTCollectionElementKindSectionFooter;

#pragma mark - CHTCollectionViewDelegateWaterfallLayout

@class CHTCollectionViewWaterfallLayout;

/**
* The CHTCollectionViewDelegateWaterfallLayout protocol defines methods that let you coordinate with a
* CHTCollectionViewWaterfallLayout object to implement a waterfall-based layout.
* The methods of this protocol define the size of items.
*
* The waterfall layout object expects the collection view’s delegate object to adopt this protocol.
* Therefore, implement this protocol on object assigned to your collection view’s delegate property.
*/
@protocol CHTCollectionViewDelegateWaterfallLayout <UICollectionViewDelegate>
@required
/**
* Asks the delegate for the size of the specified item’s cell.
*
* @param collectionView
* The collection view object displaying the waterfall layout.
* @param collectionViewLayout
* The layout object requesting the information.
* @param indexPath
* The index path of the item.
*
* @return
* The original size of the specified item. Both width and height must be greater than 0.
*/
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;

@optional
/**
* Asks the delegate for the column count in a section
*
* @param collectionView
* The collection view object displaying the waterfall layout.
* @param collectionViewLayout
* The layout object requesting the information.
* @param section
* The section.
*
* @return
* The original column count for that section. Must be greater than 0.
*/
- (NSInteger)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout columnCountForSection:(NSInteger)section;

/**
* Asks the delegate for the height of the header view in the specified section.
*
* @param collectionView
* The collection view object displaying the waterfall layout.
* @param collectionViewLayout
* The layout object requesting the information.
* @param section
* The index of the section whose header size is being requested.
*
* @return
* The height of the header. If you return 0, no header is added.
*
* @discussion
* If you do not implement this method, the waterfall layout uses the value in its headerHeight property to set the size of the header.
*
* @see
* headerHeight
*/
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout heightForHeaderInSection:(NSInteger)section;

/**
* Asks the delegate for the height of the footer view in the specified section.
*
* @param collectionView
* The collection view object displaying the waterfall layout.
* @param collectionViewLayout
* The layout object requesting the information.
* @param section
* The index of the section whose header size is being requested.
*
* @return
* The height of the footer. If you return 0, no footer is added.
*
* @discussion
* If you do not implement this method, the waterfall layout uses the value in its footerHeight property to set the size of the footer.
*
* @see
* footerHeight
*/
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout heightForFooterInSection:(NSInteger)section;

/**
* Asks the delegate for the insets in the specified section.
*
* @param collectionView
* The collection view object displaying the waterfall layout.
* @param collectionViewLayout
* The layout object requesting the information.
* @param section
* The index of the section whose insets are being requested.
*
* @discussion
* If you do not implement this method, the waterfall layout uses the value in its sectionInset property.
*
* @return
* The insets for the section.
*/
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;

/**
* Asks the delegate for the header insets in the specified section.
*
* @param collectionView
* The collection view object displaying the waterfall layout.
* @param collectionViewLayout
* The layout object requesting the information.
* @param section
* The index of the section whose header insets are being requested.
*
* @discussion
* If you do not implement this method, the waterfall layout uses the value in its headerInset property.
*
* @return
* The headerInsets for the section.
*/
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForHeaderInSection:(NSInteger)section;

/**
* Asks the delegate for the footer insets in the specified section.
*
* @param collectionView
* The collection view object displaying the waterfall layout.
* @param collectionViewLayout
* The layout object requesting the information.
* @param section
* The index of the section whose footer insets are being requested.
*
* @discussion
* If you do not implement this method, the waterfall layout uses the value in its footerInset property.
*
* @return
* The footerInsets for the section.
*/
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForFooterInSection:(NSInteger)section;

/**
* Asks the delegate for the minimum spacing between two items in the same column
* in the specified section. If this method is not implemented, the
* minimumInteritemSpacing property is used for all sections.
*
* @param collectionView
* The collection view object displaying the waterfall layout.
* @param collectionViewLayout
* The layout object requesting the information.
* @param section
* The index of the section whose minimum interitem spacing is being requested.
*
* @discussion
* If you do not implement this method, the waterfall layout uses the value in its minimumInteritemSpacing property to determine the amount of space between items in the same column.
*
* @return
* The minimum interitem spacing.
*/
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;

/**
* Asks the delegate for the minimum spacing between colums in a secified section. If this method is not implemented, the
* minimumColumnSpacing property is used for all sections.
*
* @param collectionView
* The collection view object displaying the waterfall layout.
* @param collectionViewLayout
* The layout object requesting the information.
* @param section
* The index of the section whose minimum interitem spacing is being requested.
*
* @discussion
* If you do not implement this method, the waterfall layout uses the value in its minimumColumnSpacing property to determine the amount of space between columns in each section.
*
* @return
* The minimum spacing between each column.
*/
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumColumnSpacingForSectionAtIndex:(NSInteger)section;

@end

#pragma mark - CHTCollectionViewWaterfallLayout

/**
* The CHTCollectionViewWaterfallLayout class is a concrete layout object that organizes items into waterfall-based grids
* with optional header and footer views for each section.
*
* A waterfall layout works with the collection view’s delegate object to determine the size of items, headers, and footers
* in each section. That delegate object must conform to the `CHTCollectionViewDelegateWaterfallLayout` protocol.
*
* Each section in a waterfall layout can have its own custom header and footer. To configure the header or footer for a view,
* you must configure the height of the header or footer to be non zero. You can do this by implementing the appropriate delegate
* methods or by assigning appropriate values to the `headerHeight` and `footerHeight` properties.
* If the header or footer height is 0, the corresponding view is not added to the collection view.
*
* @note CHTCollectionViewWaterfallLayout doesn't support decoration view, and it supports vertical scrolling direction only.
*/
@interface CHTCollectionViewWaterfallLayout : UICollectionViewLayout

/**
* @brief How many columns for this layout.
* @discussion Default: 2
*/
@property (nonatomic, assign) NSInteger columnCount;

/**
* @brief The minimum spacing to use between successive columns.
* @discussion Default: 10.0
*/
@property (nonatomic, assign) CGFloat minimumColumnSpacing;

/**
* @brief The minimum spacing to use between items in the same column.
* @discussion Default: 10.0
* @note This spacing is not applied to the space between header and columns or between columns and footer.
*/
@property (nonatomic, assign) CGFloat minimumInteritemSpacing;

/**
* @brief Height for section header
* @discussion
* If your collectionView's delegate doesn't implement `collectionView:layout:heightForHeaderInSection:`,
* then this value will be used.
*
* Default: 0
*/
@property (nonatomic, assign) CGFloat headerHeight;

/**
* @brief Height for section footer
* @discussion
* If your collectionView's delegate doesn't implement `collectionView:layout:heightForFooterInSection:`,
* then this value will be used.
*
* Default: 0
*/
@property (nonatomic, assign) CGFloat footerHeight;

/**
* @brief The margins that are used to lay out the header for each section.
* @discussion
* These insets are applied to the headers in each section.
* They represent the distance between the top of the collection view and the top of the content items
* They also indicate the spacing on either side of the header. They do not affect the size of the headers or footers themselves.
*
* Default: UIEdgeInsetsZero
*/
@property (nonatomic, assign) UIEdgeInsets headerInset;

/**
* @brief The margins that are used to lay out the footer for each section.
* @discussion
* These insets are applied to the footers in each section.
* They represent the distance between the top of the collection view and the top of the content items
* They also indicate the spacing on either side of the footer. They do not affect the size of the headers or footers themselves.
*
* Default: UIEdgeInsetsZero
*/
@property (nonatomic, assign) UIEdgeInsets footerInset;

/**
* @brief The margins that are used to lay out content in each section.
* @discussion
* Section insets are margins applied only to the items in the section.
* They represent the distance between the header view and the columns and between the columns and the footer view.
* They also indicate the spacing on either side of columns. They do not affect the size of the headers or footers themselves.
*
* Default: UIEdgeInsetsZero
*/
@property (nonatomic, assign) UIEdgeInsets sectionInset;

/**
* @brief The direction in which items will be rendered in subsequent rows.
* @discussion
* The direction in which each item is rendered. This could be left to right (CHTCollectionViewWaterfallLayoutItemRenderDirectionLeftToRight), right to left (CHTCollectionViewWaterfallLayoutItemRenderDirectionRightToLeft), or shortest column fills first (CHTCollectionViewWaterfallLayoutItemRenderDirectionShortestFirst).
*
* Default: CHTCollectionViewWaterfallLayoutItemRenderDirectionShortestFirst
*/
@property (nonatomic, assign) CHTCollectionViewWaterfallLayoutItemRenderDirection itemRenderDirection;

/**
* @brief The minimum height of the collection view's content.
* @discussion
* The minimum height of the collection view's content. This could be used to allow hidden headers with no content.
*
* Default: 0.f
*/
@property (nonatomic, assign) CGFloat minimumContentHeight;

/**
* @brief The calculated width of an item in the specified section.
* @discussion
* The width of an item is calculated based on number of columns, the collection view width, and the horizontal insets for that section.
*/
- (CGFloat)itemWidthInSectionAtIndex:(NSInteger)section;

@end
Loading

0 comments on commit 244cef6

Please sign in to comment.