FAPaginationLayout 2.0.1

FAPaginationLayout 2.0.1

测试已测试
语言语言 SwiftSwift
授权 MIT
发布最后发布2018 年 9 月
SPM支持 SPM

Fahid Attique 维护。



  • Fahid Attique

Alt text

Swift version Support Dependecy Manager Version License Platform

特性

  • 滚动能动调整单元格大小
  • 滚动时旋转单元格
  • 在您的集合视图中添加分页
  • 向用户显示集合有更多单元格或数据
  • 可使用集合视图的内容内边距自定义
  • 易于集成和使用

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它

$ gem install cocoapods

使用 CocoaPods 将 FAPaginationLayout 集成到您的 Xcode 项目中,在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
pod 'FAPaginationLayout'
end

然后,运行以下命令

$ pod install

用法

步骤 1

  • 根据以下说明,将集合视图流布局设置为 FAPaginationLayout,

Alt text

步骤 2(在滚动时具有单元格大小动画)

  • 设置集合视图的 contentInsets 方法

collectionView.contentInset = UIEdgeInsetsMake(0, 30, 0, 30)

  • 根据集合视图的内容边距设置集合视图的 item size,并相应地进行缩放和动画处理
override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    updateCellsLayout()
}

func updateCellsLayout()  {

    let centerX = collectionView.contentOffset.x + (collectionView.frame.size.width)/2

    for cell in collectionView.visibleCells {
        var offsetX = centerX - cell.center.x
        if offsetX < 0 {
            offsetX *= -1
        }
        cell.transform = CGAffineTransform.identity
        let offsetPercentage = offsetX / (view.bounds.width * 2.7)
        let scaleX = 1-offsetPercentage
        cell.transform = CGAffineTransform(scaleX: scaleX, y: scaleX)
    }
}


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    var cellSize: CGSize = collectionView.bounds.size

    cellSize.width -= collectionView.contentInset.left * 2
    cellSize.width -= collectionView.contentInset.right * 2
    cellSize.height = cellSize.width

    return cellSize
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    updateCellsLayout()
}

步骤 2(在滚动时具有单元格旋转动画)

  • 设置集合视图的 contentInsets 方法

collectionView.contentInset = UIEdgeInsetsMake(0, 30, 0, 30)

  • 根据集合视图的内容边距设置集合视图的 item size,并相应地进行缩放和动画处理
override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    updateCellsLayout()
}

func updateCellsLayout()  {

    let centerX = collectionView.contentOffset.x + (collectionView.frame.size.width)/2

    for cell in collectionView.visibleCells {

        var offsetX = centerX - cell.center.x
        if offsetX < 0 {
            offsetX *= -1
        }

        if offsetX > 0 {

            let offsetPercentage = offsetX / view.bounds.width
            let rotation = 1 - offsetPercentage
            cell.transform = CGAffineTransform(rotationAngle: rotation - 45)
        }
    }
}


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    var cellSize: CGSize = collectionView.bounds.size

    cellSize.width -= collectionView.contentInset.left * 2
    cellSize.width -= collectionView.contentInset.right * 2
    cellSize.height = cellSize.width

    return cellSize
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    updateCellsLayout()
}

步骤 2(没有单元格大小动画)

  • 根据您的需要设置 collectionView 的内容边距

collectionView.contentInset = UIEdgeInsetsMake(0, 20, 0, 20)

  • 根据集合视图的内容边距设置集合视图的 item size。
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    var cellSize: CGSize = collectionView.bounds.size
    cellSize.width -= collectionView.contentInset.left
    cellSize.width -= collectionView.contentInset.right

    return cellSize
}
  • 现在运行 Xcode 项目,享受其中吧!

许可证

本项目采用 MIT 许可证授权。

作者

法希德·阿蒂骑士 - https://github.com/fahidattique55

贡献者

Evyasafmordechai - https://github.com/Evyasafmordechai orlandoamorim - https://github.com/orlandoamorim