uview 瀑布流_GitHub - loirou/YJWaterFlowLayout: 横向纵向瀑布流布局,可拖拽item,可添加头视图和脚视图...

本文介绍了如何在iOS应用中使用YJWaterFlowLayout库创建横向纵向瀑布流布局,并支持拖拽item。该库通过CocoaPods安装,提供了丰富的自定义选项,如设置流间距、item间距、头视图和脚视图大小等。通过代理方法,可以实现动态调整布局和拖拽功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

YJWaterFlowLayout

Example

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

Requirements

Installation

YJWaterFlowLayout is available through CocoaPods. To install

it, simply add the following line to your Podfile:

pod "YJWaterFlowLayout", :git => 'https://github.com/Zyj163/YJWaterFlowLayout.git'

Use

属性:

waterCount

瀑布流的条数,默认为2(优先级低于代理方法中的设置)

minimumWaterSpacing

流间距,默认是10(优先级低于代理方法中的设置)

minimumItemSpacing

同一流中item间距,默认是10(优先级低于代理方法中的设置)

headerSize

section头视图大小,默认没有(优先级低于代理方法中的设置)

footerSize

section脚视图大小,默认没有(优先级低于代理方法中的设置)

hasSectionBackground

是否包含section背景图,默认没有(优先级低于代理方法的设置)

sectionInset

section内边距,默认没有(优先级低于代理方法中的设置)

layoutDirection

流动方向,默认纵向

unionSize

批量布局个数,可以根据一屏最多可以显示多少个item来设置,默认20

delegate 代理

moveAction 拖拽代理

流条数,可选实现,如果没有实现,使用属性waterCount,返回<=0当作未实现处理

unc collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: YJWaterFlowLayout, waterCountForSection section: Int) -> Int

是否含有background,可选实现

func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: YJWaterFlowLayout,

hasBackgroundInSection section: Int) -> Bool

根据返回的size计算宽高比,必须实现

func collectionView (_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,

sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize

头视图/脚视图大小,可选实现

func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: YJWaterFlowLayout,

sizeForHeaderForFooterInSection section: Int, elementKind: String) -> CGSize

返回section中内边距,可选实现,如果没有实现,使用属性sectionInset

func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,

insetForSectionAtIndex section: NSInteger) -> UIEdgeInsets

返回section中同一流中item的间距,可选实现,如果没有实现,使用属性minimumItemSpacing

func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,

minimumItemSpacingForSection section: NSInteger) -> CGFloat

返回section中流间距,可选实现,如果没有实现,使用属性minimumWaterSpacing

func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,

minimumWaterSpacingForSection section: NSInteger) -> CGFloat

流宽度,可选实现,如果没有实现根据contentInsets、minimumWaterSpacing、waterCount计算得来,返回<=0当作未实现处理

func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: YJWaterFlowLayout,

waterWidthForSection section: Int, at index: Int) -> CGFloat

修改attributes,background/header/footer/item, kind为nil时为item,可选实现

func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: YJWaterFlowLayout,

relocationForElement kind: String?, currentAttributes: UICollectionViewLayoutAttributes)

拖拽需要实现的方法

extension ViewController: YJWaterLayoutMovable {

func enableMoveItem(_ layout: YJWaterFlowLayout) -> Bool {

return true

}

}

func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {

(collectionView.collectionViewLayout as! YJWaterFlowLayout).moveItem(&datas, moveItemAt: sourceIndexPath, to: destinationIndexPath)

}

YJCollectionSectionHeader header的类型string

YJCollectionSectionFooter footer的类型string

YJCollectionSectionBackground background的类型string

以上三种类型用来替换系统提供的UICollectionElementKindSectionHeader等,用法相同,具体可查看demo

YJCollectionAutoInt: Int = 0

YJCollectionAutoFloat: Float = 0

YJCollectionAutoCGFloat: CGFloat = 0

YJCollectionAutoSize: CGSize = CGSize.zero

YJCollectionAutoInsets: UIEdgeInsets = UIEdgeInsets.zero

Author

License

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值