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

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

  • 相关阅读:
    函数阶乘累加求和
    函数
    枚举
    变量定义在主函数外面
    输入班级人数,姓名,分数,创建集合,并按照表格样式打印出来
    控制台输入输出
    Chapter 4、流程控制(一)--- 条件语句 (23rd,Feb)
    实战练习P62 ---比较大小,求矩形面积
    Chapter 3、Java语法基础(三)--- 运算符、数据类型转换 (22nd,Feb)
    字符集
  • 原文地址:https://www.cnblogs.com/chinaxxren/p/ios.html
Copyright © 2011-2022 走看看