zoukankan      html  css  js  c++  java
  • 音频输入大小变化图

    接上文。这是当音频输入后用一个表示音频输入的大小变化的view

    这个没有什么可以说的,直接上代码

    #import <Foundation/Foundation.h>
    
    @interface AVMeterView : UIView {
        float peakPowerForChannel;
        float h;
    }
    
    @property(nonatomic,assign) float peakPowerForChannel;
    
    - (id)initWithFrame:(CGRect)frame;
    
    @end
    #import "AVMeterView.h"
    #import <CoreGraphics/CoreGraphics.h>
    #import <QuartzCore/QuartzCore.h>
    
    @implementation AVMeterView
    
    @synthesize peakPowerForChannel;
    
    - (void)dealloc {
        [ super dealloc ];
    }
    
    - (id)initWithFrame:(CGRect)frame {
        self = [ super initWithFrame: frame ];
        if (self != nil) {
            self.backgroundColor = [UIColor clearColor];
            h = 100;
            self.layer.cornerRadius = 8;
            self.layer.masksToBounds = YES;
        }
        return self;
    }
    
    - (void)drawRect:(CGRect)rect {
        CGRect viewBounds = self.bounds;
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextClearRect(context, viewBounds);
        CGContextSetFillColor(context, CGColorGetComponents([UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5].CGColor));
        CGContextFillRect(context, viewBounds);
        CGContextSetLineWidth(context,5);
        CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
        if (peakPowerForChannel > 50) {
            peakPowerForChannel = 50;
        }
        
        
        for (int i= 20; i <= peakPowerForChannel * 1.2; i = i+ 10) {
            float hs = sqrtf(2) * i;
            float p = h/sqrtf(2);
            float p1 = (hs)/2;
            CGContextMoveToPoint(context,p - p1,h - p1);
            CGContextAddArcToPoint(context,p,h - hs,p + p1,h - p1,i);
        }
        CGContextStrokePath(context);
        // add image
        CGContextTranslateCTM(context, 0, viewBounds.size.height);
        CGContextScaleCTM(context, 1, -1);
        UIImage *image = [UIImage imageNamed:@"mike.png"];
        CGFloat x = self.bounds.size.width - image.size.width;
        CGContextDrawImage(context, CGRectMake(x*0.5,10, 34, 44), image.CGImage);
    }
    
    @end

    出来的图片就是中间那部分。其实啪啪和微信都差不多是这样子做的,很简单的。

  • 相关阅读:
    使用Eolinker拓展API设计
    如何记录API
    API设计
    【翻译】通过API主导的集成来证明您的业务未来
    从状态库迁移分布系统建设方式
    PostgreSql 查询某个模式下面的所有表
    迁移状态库的地市区县信息
    测开和开发的难度对比
    yum源的三种搭建方式
    Harbor实现容器镜像仓库的管理和运维
  • 原文地址:https://www.cnblogs.com/chinaxxren/p/ios.html
Copyright © 2011-2022 走看看