【问题标题】:Enlarge / Shrink UIImage with sound capture Swift使用声音捕捉 Swift 放大/缩小 UIImage
【发布时间】:2018-04-30 15:50:15
【问题描述】:

你知道一个库/技巧可以让我根据声音创建我的按钮(圆形)动画吗?

我有一个音乐应用程序,其中我的录音按钮是圆形的,我希望它根据歌曲的强度放大或缩小。

假设它看起来有点像没有波浪的 Shazam 按钮。

感谢您的帮助,

【问题讨论】:

    标签: ios swift animation button audio


    【解决方案1】:

    你会想做这样的事情:

    func animateRecordButton() {
    
        if let button = self.recordButton {
            UIView.animate(withDuration: 0.2, delay: 0, options: [.allowUserInteraction], animations: {
    
                if self.scaledDown {
                    button.transform = CGAffineTransform.identity
                } else {
                    button.transform = CGAffineTransform(scaleX: self.amplitude, y: self.amplitude)
                }
            }, completion: { (done) in
    
                self.scaledDown = !self.scaledDown
    
                if !self.recordingStopped {
                    //Generate new x and y value from the audio waveform's amplitude.
                    //You'll need to make sure that it makes sense for your animation.
                    self.amplitude = getAmplitudeValueFromWaveform()
    
                    self.animateRecordButton()
                } else {
                    if let button = recordButton {
                        button.transform = CGAffineTransform.identity
                    }
                }
            })
        }
    }
    

    我确信还有其他关于音频 SDK 的方法,但我没有使用它。音频 SDK 中可能有一些方法已经可以为您处理这类事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-12
      相关资源
      最近更新 更多