RecordButtonSwift 0.0.4

RecordButtonSwift 0.0.4

测试已测试
语言语言 SwiftSwift
许可 MIT
发布最新发布2017年12月
SwiftSwift 版本3.0
SPM支持 SPM

Omer Karisman 维护。



RecordButton

这是 iOS 按钮,类似于 Apple 的 VoiceRecorder 应用中的录音按钮。在录音时,它还会显示录音过程。对于具有固定/最大长度的视频录制应用(如 snapchat、vine、instragram)非常适用。

它包含开始和停止声音。

Example

安装

RecordButton 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中。
为了安装,只需将以下行添加到您的 Podfile 中

pod "RecordButtonSwift"

在您想要使用此模块的文件顶部添加此行 import 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()
    }
    

作者

Omer Karisman

MojiLaLa 的 UI/UX Lead @ MojiLaLa
Twitter Dribble Github
Sahin Boydas

MojiLaLa 的联合创始人 @ MojiLaLa
LinkedIn

灵感来自

samuelbeek,http://samuelbeek.com
alldritt,http://markalldritt.com