CSStickyHeaderFlowLayout

简介:

https://github.com/jamztang/CSStickyHeaderFlowLayout

 

Parallax, Sticky Headers, Growing image heading, done right in one UICollectionViewLayout.

视差效果,悬停的headerView以及实时变化的headerView,一个UICollectionViewLayout就可以实现.

 

Installation

CSStickyHeaderFlowLayout is available through CocoaPods, to install it simply add the following line to your Podfile:

你可以通过 CocoaPods 来安装 CSStickyHeaderFlowLayout, 在你的 Podfile 里面添加这么一句话即可:

pod "CSStickyHeaderFlowLayout"

Alternatively, you can just drag the files from CSStickyHeaderFlowLayout / Classes into your own project.

当然,你也可以将 CSStickyHeaderFlowLayout 文件夹拖到你的项目当中.

 

Usage (Swift/Code)

Documentation is coming soon. For now please open CSStickyHeaderFlowLayout.xcworkspace > SwiftDemo target.

很快就会有文档了.你可以先通过运行项目来熟悉api.

 

Usage (CocoaPods/Objective-C/Storyboard)

To run the example project; clone the repo, and run pod install from the Project directory first.

你需要先获取项目,然后在项目目录中先运行 pod install.

1. Setting up the Sticky Section Header

Configure your collection view to use CSStickyHeaderFlowLayout. Here's an example on how you to do it in Storyboard.

将你的 collection view 配置成 CSStickyHeaderFlowLayout, 参考下图:

Now all your section headers will get the sticky effect like table view. You can disable it with one line of code.

现在,你所有的 section header 将会获得悬停效果, 你也可以通过一行代码来禁止这种效果.

@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:

用 supplementary views 来作为视差效果的header, 下面是一个如何使用nib来实现这种效果的例子.

Register that nib file to your collection view controller in code:

然后在你的 collection view 的控制器里面注册这个 nib 文件:

#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 -[UICollectionViewDataSource collectionView:viewForSupplementaryElementOfKind:atIndexPath:]

实现 -[UICollectionViewDataSource collectionView:viewForSupplementaryElementOfKind:atIndexPath:]

- (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

配置其他效果跟你配置 header cell 类似, 通过在 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.

运行这个项目,然后你就可以看到这些效果了.

 

Donation

If you think this worths something, tip me a cup of coffee! (p.s. was trying out ChangeTip, or if you know any better donation button, let me know) :)

 

Updates

  • 0.2.10: Fixed issue because attributes were not copied and datasource might have been niled

  • 0.2.9: Remove Supplementry Header Layout Attribute to prevent crash when returning nil and while is CGSizeZero

  • 0.2.8: Fixed a visual issue when animating contentInsets #85 and crash when dragging cells #69

  • 0.2.7: Fixed scroll indicator covered by cell

  • 0.2.6: Fixing that section header being covered by cell after perform batch update

  • 0.2.5: Fixing a crash when quickly popping back to a view controller using the parallax header

  • 0.2.4: Possibly fix for a crash when parallaxHeaderReferenceSize is changed

  • 0.2.3: Enabled iPhone 6 screen sizes, reverted a patch and fixed a visual bug and content tapping bug.

  • 0.2.2: Fix 1px header and zIndex problem, thanks @m1entus and @Xyand

  • 0.2.1: Fix crash on reloadData in collection view when header is offscreen, thanks @jessesquires

  • 0.2: Added custom UICollectionViewLayoutAttributes to support more advanced example (Spotify App)

  • 0.1.1: Minor fixes for default number of sections, thanks @miwillhite

  • 0.1: Initial Release

 

Who's using it?

We've a wiki page for that, feel free to add your projects there!

 

Requirements

  • Xcode 5
  • iOS 7 (I haven't really test on iOS 6 but it should work if you're using iOS 6 compatible Storyboard)

 

Author

James Tang, j@jamztang.com

 

License

CSStickyHeaderFlowLayout is available under the MIT license. See the LICENSE file for more info.

 

目录
相关文章
|
8月前
|
网络协议 程序员 调度
即时通讯技术文集(第33期):IM开发综合技术合集(Part6) [共12篇]
为了更好地分类阅读 52im.net 总计1000多篇精编文章,我将在每周三推送新的一期技术文集,本次是第33 期。
81 0
|
8月前
|
Swift iOS开发 UED
【Swift开发专栏】Swift中的动画与过渡效果
【4月更文挑战第30天】本文介绍了Swift中的动画与过渡效果,分为三个部分:动画基础、过渡效果和实战案例。在第一部分,讲解了动画概念,包括UIView动画、动画选项和关键帧动画。第二部分阐述了过渡效果,包括UIView自带的过渡效果和自定义过渡效果。第三部分通过按钮点击动画和页面切换过渡效果展示了实际应用。
167 0
|
8月前
|
Web App开发 JSON 小程序
苹果app开发apple-app-site-association文件配置
apple-app-site-association 是苹果的配置文件,用于建立app和网站关联,支持Universal Links,使点击网站链接能直接打开相应app内部页面。配置文件为JSON格式,需上传至服务器`.well-known`目录或根目录。通过检查三个链接来测试配置,确保Content-Type为`application/json`。成功配置后,点击链接能在iPhone备忘录或Safari中直接唤起app,但可能有24-48小时延迟。
2054 6
|
前端开发 JavaScript
vue 使用canvas画布
vue 使用canvas画布
333 0
|
Swift
SwiftUI极简教程32:使用Shape形状和Animation动画创建一个圆形进度条
SwiftUI极简教程32:使用Shape形状和Animation动画创建一个圆形进度条
829 0
SwiftUI极简教程32:使用Shape形状和Animation动画创建一个圆形进度条
|
iOS开发 数据格式
iOS - Quartz 2D 第三方框架 Charts 绘制图表
1、Charts 简介 使用第三方框架 Charts 绘制 iOS 图表。GitHub 源码 Charts Charts 是一款用于绘制图表的框架,可以绘制柱状图、折线图、K线图、饼状图等。Charts 只有 Swift 版本。
2739 0
|
iOS开发
(转载)教你如何在iOS项目中设置各种字体
原文地址:http://www.cnblogs.com/jijiYY/p/4736967.html 在iOS开发中设置字体的方法有很多种,下面为大家介绍比较常用的三种方法 1.
1478 0
|
Android开发 iOS开发
iOS实现点击图片放大&长按保存图片
在项目中免不了会遇到,实名认证上传身份证、绑定银行卡等功能。在实际操作中呢,会涉及到上传图片,在页面布局时,可能图片不是一张,考虑到布局的美观等因素,显示图片的位置变得很小,如果想查看上传的图片是否清晰,内容是否完整,可能就需要放大才能实现,下面就和大家分享一下我封装的一类,完美的实现了图片的缩放功能。
388 0
|
编解码 Swift iOS开发
SwiftUI极简教程24:构建一个Banner图片轮播(上)
SwiftUI极简教程24:构建一个Banner图片轮播(上)
1087 0
SwiftUI极简教程24:构建一个Banner图片轮播(上)
|
定位技术 开发工具 Android开发
Android 定位之百度地图定位 问题总结
Android 定位之百度地图定位 问题总结
Android 定位之百度地图定位 问题总结

热门文章

最新文章