SpinWheelControl 0.2.0

SpinWheelControl 0.2.0

测试已测试
语言语言 SwiftSwift
许可证 未知
发布最新版本2018 年 8 月
SPM支持 SPM

Josh Henry维护。



  • Josh Henry

Spin Wheel Control v0.2.0

概述

Spin Wheel Control 是一种惯性旋转轮 UI 控件,允许选择一个项目。它用 Swift 编程语言编写,可用于 iOS 应用。

代码是基于 Cesare Rocchi 和 Simone Civetta 编写的 Objective-C "SMWheelControl" CocoaPod 的 Swift 衍生、移植和改进,可在此处找到。

如果您的应用中使用了 SpinWheelControl,请告诉我,因为我想看看它!

主要使用的语言和技术:Swift、UIKit、核心动画、CocoaPods、界面构建器、Xcode

要求

  • iOS 10.0+
  • Xcode 9.0+
  • Swift 4.0+

安装

要在您的机器上运行此软件

  • 在您的机器上安装 Cocoapods

  • 在项目根目录下创建一个Podfile文件,并在其中添加该行到目标文件内。

pod 'SpinWheelControl'
  • 在项目根目录下,通过命令行运行pod install。

包含此控件到Swift项目中无需额外配置。

为了让此控件在Objective-C项目中工作

  • 在项目的构建设置(而非目标构建设置)中,将标记“ Defines Module”设置为“是”。

  • 通过查找目标(而非项目)的构建设置中“Project Module Name”,来找到你的产品模块名称。

  • 将SpinWheelControl文件添加到你的项目中。

  • 在你的所有Objective-C类中导入 <productModuleName-Swift.h>。当你在Objective-C项目中包含Swift类时,此文件由编译器自动生成。

用法

确保包含SpinWheelControl的视图控制器遵循SpinWheelControlDataSource和SpinWheelControlDelegate协议

class ViewController: UIViewController, SpinWheelControlDataSource, SpinWheelControlDelegate

可以通过将SpinWheelControlView拖放到Interface Builder中创建输出符号,或者用以下代码通过代码实例化UI控件

let frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.width)

spinWheelControl = SpinWheelControl(frame: frame)

添加valueChanged事件的针对目标

spinWheelControl.addTarget(self, action: #selector(spinWheelDidChangeValue), for: UIControlEvents.valueChanged)

为SpinWheelControl提供一个数据源

spinWheelControl.dataSource = self

spinWheelControl.reloadData()

设置SpinWheelControl的委托

spinWheelControl.delegate = self

将SpinWheelControl添加到你的视图中

self.view.addSubview(spinWheelControl)

以给定速度乘数(介于0和1之间,默认为0.75)旋转轮子

spinWheelControl.spin(velocityMultiplier: CGFloat)

随机旋转轮子

spinWheelControl.randomSpin()

数据源方法

以下数据源方法可用

//Specify the number of wedges in the spin wheel by returning a positive value that is greater than 1

func numberOfWedgesInSpinWheel(spinWheel: SpinWheelControl) -> UInt


//Returns the SpinWheelWedge at the specified index of the SpinWheelControl

func wedgeForSliceAtIndex(index: UInt) -> SpinWheelWedge

委托方法

以下委托方法可用

//Triggered when the spin wheel control has come to rest after spinning.

func spinWheelDidEndDecelerating(spinWheel: SpinWheelControl)


//Triggered at various intervals. The variable radians describes how many radians the spin wheel control has moved since the last time this method was called.

func spinWheelDidRotateByRadians(radians: CGFloat)

属性

以下属性可进行修改

borderWidth - The width of the border around the spin wheel
borderColor - The color of the border around the spin wheel
cornerRadius - Set with a CGFloat value to round the edges of the border around the spin wheel
snapOrientation - The direction in which the wheel "snaps" (SpinWheelDirection.up, SpinWheelDirection.right, SpinWheelDirection.down, or SpinWheelDirection.left)
wedgeLabelOrientation - The orientation of labels in each wedge (WedgeLabelOrientation.inOut or WedgeLabelOrientation.around)

示例应用

要查看 SpinWheelControl 的实际效果,请打开 SpinWheelExample 文件夹中的示例项目。

作者

Josh Henry - Big Smash Software

基于由 Cesare Rocchi 和 Simone Civetta 编写的 Objective-C "SMWheelControl" CocoaPod,可以在此处找到。

许可

BSD 3-Clause