在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:CSStickyHeaderFlowLayout/CSStickyHeaderFlowLayout开源软件地址:https://github.com/CSStickyHeaderFlowLayout/CSStickyHeaderFlowLayout开源编程语言:Objective-C 78.2%开源软件介绍:CSStickyHeaderFlowLayoutContributorsFor anyone who'd like to be a contributor to the repository, please read the Contribution Guideline Parallax, Sticky Headers, Growing image heading, done right in one UICollectionViewLayout. InstallationCocoapodsCSStickyHeaderFlowLayout is available through CocoaPods, to install it simply add the following line to your Podfile:
CarthageCSStickyHeaderFlowLayout is also available with Carthage.
Add Alternatively, you can just drag the files from Usage (Swift/Code)Documentation is coming soon. For now please open Usage (CocoaPods/Objective-C/Storyboard)To run the example project; clone the repo, and run 1. Setting up the Sticky Section Header Configure your collection view to use Now all your section headers will get the sticky effect like table view. You can disable it with one line of code. @property (nonatomic) BOOL disableStickyHeaders; 2. Setting up the Collection View Header We'll be using supplementary views for our parallax header. Here's an example on how use a nib file for that purpose: Register that nib file to your collection view controller in code: #import "CSStickyHeaderFlowLayout.h"
- (void)viewDidLoad {
[super viewDidLoad];
// Locate your layout
CSStickyHeaderFlowLayout *layout = (id)self.collectionViewLayout;
if ([layout isKindOfClass:[CSStickyHeaderFlowLayout class]]) {
layout.parallaxHeaderReferenceSize = CGSizeMake(320, 200);
}
// Locate the nib and register it to your collection view
UINib *headerNib = [UINib nibWithNibName:@"CSGrowHeader" bundle:nil];
[self.collectionView registerNib:headerNib
forSupplementaryViewOfKind:CSStickyHeaderParallaxHeader
withReuseIdentifier:@"header"];
} Implement - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
// Check the kind if it's CSStickyHeaderParallaxHeader
if ([kind isEqualToString:CSStickyHeaderParallaxHeader]) {
UICollectionReusableView *cell = [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:@"header"
forIndexPath:indexPath];
return cell;
} else if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
// Your code to configure your section header...
} else {
// other custom supplementary views
}
return nil;
} That's it. You'll be able to get the header you wanted using the best practice. Configuring other effects are really just the way how you setup the header cell, by combining different settings in the minimal exposed properties in CSStickyHeaderFlowLayout.h @property (nonatomic) CGSize parallaxHeaderReferenceSize;
@property (nonatomic) CGSize parallaxHeaderMinimumReferenceSize;
@property (nonatomic) BOOL disableStickyHeaders; Run the project examples and it'll shows you exactly how you achieve different effects. Updates
Who's using it?We've a wiki page for that, feel free to add your projects there! Requirements
AuthorJames Tang, [email protected] LicenseCSStickyHeaderFlowLayout is available under the MIT license. See the LICENSE file for more info. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论