Donut 是一个用来环形排列视图的库,就像甜甜圈一样。
您可以用它轻松地,这将为您带来美妙的体验。
此库灵感来源于 EMCarousel。
Swift3
最好将 UIViewController 的视图的框架设置为 donutView 的框架。
如果您想移动 donutView 的中心点,请使用 setCenterDiff(CGPoint(x: #X_Diff, y: #Y_Diff))
。
如果您想更改 DonutView 的倾斜度,请使用 setCarouselInclination(angleX: #AngleX, angleZ: #AngleZ)
。
您可以改变 X 和 Z 角度。
#AngleX = -.pi / 8.0 | #AngleZ = -.pi / 4.0 |
---|---|
![]() | ![]() |
如果您想更改前后 DonutViewCells 的透明度,请使用 setFrontCellAlpha(#AlphaFront)
或 setBackCellAlpha(#AlphaBack)
。
#AlphaFront = 1.0, #AlphaBack = 0.7 | #AlphaFront = 0.7, #AlphaBack = 1.0 |
---|---|
![]() | ![]() |
您可以通过 setSelectableCell(Bool)
来设置 DonutView 是否可选。
如果单元格可选,选中的单元格将滚动到中心。
您可以通过 setCellAlignmentCenter(Bool)
来设置 DonutView 的对齐是否为中心。
true | 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
}
如果您想知道中心单元格变化或选中的单元格,可以使用以下代理方法。
optional func donutView(_ donutView: DonutView, didChangeCenter cell: DonutViewCell)
optional func donutView(_ donutView: DonutView, didSelect cell: DonutViewCell)
您可以向 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)")
}
}
Donut 可通过 CocoaPods 获取。
要安装
,只需将以下行添加到您的 Podfile
pod "Donut"
将 Donut 目录添加到您的项目中。
Keisuke Tatsumi
Donut 基于 MIT 许可证。
有关更多信息,请参阅 LICENSE 文件。