音频输入大小变化图

接上文。这是当音频输入后用一个表示音频输入的大小变化的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

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

 

转载于:https://www.cnblogs.com/chinaxxren/archive/2013/01/16/ios.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值