iOS音频频谱动画,仿QQ录音频谱

先上效果图:

display.gif

有需要的请移步GitHub下载:
https://github.com/HuangGY1993/GYSpectrum

用法很简单,示例:

SpectrumView * spectrumView = [[SpectrumView alloc] initWithFrame:CGRectMake(CGRectGetMidX(self.view.frame) - 100,180,200, 40.0)];
spectrumView.text = [NSString stringWithFormat:@"%d",0];
__weak SpectrumView * weakWaver = spectrumView;
spectrumView.itemLevelCallback = ^() {

[self.audioRecorder updateMeters];

//取得第一个通道的音频,音频强度范围是-160到0
float power = [self.audioRecorder averagePowerForChannel:0];
weakWaver.level = power;

};
[self.view addSubview:spectrumView];

使用前请注意:

SpectrumView.frame.size.width / SpectrumView.numberOfItems >= 5

默认SpectrumView.numberOfItems = 20 (可修改,必须为偶数),所以SpectrumView.frame.size.width默认要大于100
例如:SpectrumView * spectrumView = [[SpectrumView alloc] initWithFrame:CGRectMake(0,0,100,40)];


作者:Genie_GY
链接:https://www.jianshu.com/p/502c69062d9e
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
posted @ 2019-05-17 18:38  brave-sailor  阅读(758)  评论(0编辑  收藏  举报