Donut 1.0.1

Donut 1.0.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2017年9月
SwiftSwift 版本3.0
SPM支持 SPM

cokaholic 维护。



Donut 1.0.1

概述

Donut 是一个用来环形排列视图的库,就像甜甜圈一样。

您可以用它轻松地,这将为您带来美妙的体验。

此库灵感来源于 EMCarousel

内容

特性





  • 动画项目选择
  • 带动画添加项
  • 支持自动单元格对齐中心
  • 支持 3D 斜倾角度 (x, z)
  • 支持动画曲线 (线性,橡皮筋,橡皮筋入,橡皮筋出)
  • 支持 Interface Builder
  • 支持 Swift3
  • 等等...

在浏览器中运行示例应用

用法

1. 框架大小和中心差值

最好将 UIViewController 的视图的框架设置为 donutView 的框架
如果您想移动 donutView 的中心点,请使用 setCenterDiff(CGPoint(x: #X_Diff, y: #Y_Diff))

2. 设置配置

倾斜度

如果您想更改 DonutView 的倾斜度,请使用 setCarouselInclination(angleX: #AngleX, angleZ: #AngleZ)
您可以改变 X 和 Z 角度。

#AngleX = -.pi / 8.0 #AngleZ = -.pi / 4.0
x-pi_8 z-pi_4

单元格透明度

如果您想更改前后 DonutViewCells 的透明度,请使用 setFrontCellAlpha(#AlphaFront)setBackCellAlpha(#AlphaBack)

#AlphaFront = 1.0, #AlphaBack = 0.7 #AlphaFront = 0.7, #AlphaBack = 1.0
f10_b07 f07_b10

可选

您可以通过 setSelectableCell(Bool) 来设置 DonutView 是否可选。
如果单元格可选,选中的单元格将滚动到中心。

自动单元格对齐中心

您可以通过 setCellAlignmentCenter(Bool) 来设置 DonutView 的对齐是否为中心。

true false
alignment_center_true alignment_center_false

后单元格交互启用

您可以通过 setBackCellInteractionEnabled(Bool) 来设置 DonutView 的后单元格交互是否启用。

仅单元格交互启用

您可以通过 setOnlyCellInteractionEnabled(Bool) 来设置 DonutView 的交互是否仅限于单元格。

动画曲线

如果您想更改 DonutView 的动画曲线,请使用 setAnimationCurve(UIViewAnimationCurve)
您可以从以下列表中选择一个动画曲线。

public enum UIViewAnimationCurve : Int {

    case easeInOut  // slow at beginning and end

    case easeIn     // slow at beginning

    case easeOut    // slow at end

    case linear
}

3. DonutViewDelegate(如果有必要)

如果您想知道中心单元格变化或选中的单元格,可以使用以下代理方法。

optional func donutView(_ donutView: DonutView, didChangeCenter cell: DonutViewCell)
optional func donutView(_ donutView: DonutView, didSelect cell: DonutViewCell)

4. 添加单元格

您可以向 DonutView 添加一个或多个继承自 DonutViewCell 的单元格。
请注意!:在添加单元格之前,您需要设置要添加的单元格的框架大小!!!
如果您想添加单元格,请使用 addCell(_ cell: DonutViewCell)addCells(_ cells: [DonutViewCell])

class ViewController: UIViewController, DonutViewDelegate {
  private let donutView = DonutView()
  
  override func viewDidLoad() {
        super.viewDidLoad()
        
        donutView.frame = view.bounds                   // It's better
        donutView.setCenterDiff(CGPoint(x: 0, y: 0))    // Set center diff
        donutView.setFrontCellAlpha(1.0)                // Set front cells alpha
        donutView.setBackCellAlpha(0.7)                 // Set back cells alpha
        donutView.setSelectableCell(true)               // Set selectable
        donutView.setCellAlignmentCenter(true)          // Set auto cell alignment center
        donutView.setBackCellInteractionEnabled(false)  // Set back cells interaction
        donutView.setOnlyCellInteractionEnabled(true)   // Set only cells interaction
        donutView.setAnimationCurve(.linear)            // Set animation curve
        donutView.addCells(getCardCells())              // Add cells

        donutView.delegate = self                       // Set delegate
        view.addSubview(donutView)
  }
  
  // MARK: - DonutViewDelegate

  func donutView(_ donutView: DonutView, didChangeCenter cell: DonutViewCell) {
      print("current center cell: \(cell)")
  }

  func donutView(_ donutView: DonutView, didSelect cell: DonutViewCell) {
      print("selected cell: \(cell)")
  }
}

查看 示例 了解更多细节。

需求

  • Xcode 8.0+
  • Swift 3.0+
  • iOS 9.0+

安装

CocoaPods

Donut 可通过 CocoaPods 获取。
要安装
,只需将以下行添加到您的 Podfile

pod "Donut"

手动

Donut 目录添加到您的项目中。

作者

Keisuke Tatsumi

许可证

Donut 基于 MIT 许可证。
有关更多信息,请参阅 LICENSE 文件