测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年2月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Samuel Beek 维护。
Swift 中的录制按钮。受 SDRecordButton 启发,在录制时显示录制过程。它非常适合拥有固定/最大长度的视频录制应用,如 Snapchat、Vine、Instagram。
iOS 8 以及更高版本
要运行示例项目,首先克隆仓库,然后在 Example 目录下运行 pod install
。
RecordButton 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile:
pod "RecordButton"
将此行添加到您想要使用此模块的文件顶部 import RecordButton
添加到 viewDidLoad
let recordButton = RecordButton(frame: CGRectMake(0,0,70,70))
view.addSubview(recordButton)
最容易的方式是查看示例项目。
要更新进度,RecordButton 必须是类的一个实例。您还应添加一个 progressTimer
和一个 progress
变量,如下所示:
class ViewController: UIViewController {
var recordButton : RecordButton!
var progressTimer : NSTimer!
var progress : CGFloat! = 0
// rest of viewController
recordButton 需要一个目标来开始和停止进度计时器。在初始化 recordButton 之后(通常在 viewDidLoad()
)添加此代码:
recordButton.addTarget(self, action: "record", forControlEvents: .TouchDown)
recordButton.addTarget(self, action: "stop", forControlEvents: UIControlEvents.TouchUpInside)
最后,将这些函数添加到您的 ViewController 中:
func record() {
self.progressTimer = NSTimer.scheduledTimerWithTimeInterval(0.05, target: self, selector: "updateProgress", userInfo: nil, repeats: true)
}
func updateProgress() {
let maxDuration = CGFloat(5) // max duration of the recordButton
progress = progress + (CGFloat(0.05) / maxDuration)
recordButton.setProgress(progress)
if progress >= 1 {
progressTimer.invalidate()
}
}
func stop() {
self.progressTimer.invalidate()
}
如果您有任何问题,请不要犹豫,创建一个 issue。
samuelbeek - iOS 开发者、顾问和偶尔的设计师
此按钮受到了SDRecordButton的很大启发,由Sebyddd创建
RecordButton可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。