绘制播放音乐时的音波图形的View

这个效果类似于这个哦:

效果如下:

源码:

MusicView.h 与 MusicView.m

//
// MusicView.h
// Music
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import <UIKit/UIKit.h> @interface MusicView : UIView @property (nonatomic, assign) CGFloat progress; // 进程百分比,取值为[0,1]
@property (nonatomic, assign) CGFloat timeInterval; // 时间间隔 @end
//
// MusicView.m
// Music
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "MusicView.h" @interface MusicView () @property (nonatomic, assign) CGRect baseRect; // 备份原始的frame值 @end @implementation MusicView - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_baseRect = frame;
}
return self;
} @synthesize progress = _progress;
- (void)setProgress:(CGFloat)progress
{
if (progress <= ) {
_progress = ;
} else if (progress >= ) {
_progress = ;
} else {
_progress = progress;
} [UIView animateWithDuration:(_timeInterval > ? _timeInterval : 0.99) animations:^{
CGRect rect = _baseRect;
rect.size.height *= _progress;
self.frame = rect;
}];
}
- (CGFloat)progress
{
return _progress;
} @end

使用时的情形:

//
// RootViewController.m
// Music
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h"
#import "MusicView.h" @interface RootViewController () @property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, strong) MusicView *musicViewLine1;
@property (nonatomic, strong) MusicView *musicViewLine2;
@property (nonatomic, strong) MusicView *musicViewLine3; @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; // 线条1
_musicViewLine1 = [[MusicView alloc] initWithFrame:CGRectMake(, , , )];
_musicViewLine1.backgroundColor = [UIColor redColor];
_musicViewLine1.timeInterval = 0.5f;
[self.view addSubview:_musicViewLine1]; // 线条2
_musicViewLine2 = [[MusicView alloc] initWithFrame:CGRectMake(, , , )];
_musicViewLine2.backgroundColor = [UIColor redColor];
_musicViewLine2.timeInterval = 0.5f;
[self.view addSubview:_musicViewLine2]; // 线条3
_musicViewLine3 = [[MusicView alloc] initWithFrame:CGRectMake(, , , )];
_musicViewLine3.backgroundColor = [UIColor redColor];
_musicViewLine3.timeInterval = 0.5f;
[self.view addSubview:_musicViewLine3]; _timer = [NSTimer scheduledTimerWithTimeInterval:0.5f
target:self
selector:@selector(timerEvent)
userInfo:nil
repeats:YES];
} - (void)timerEvent
{
_musicViewLine1.progress = arc4random()%/.f;
_musicViewLine2.progress = arc4random()%/.f;
_musicViewLine3.progress = arc4random()%/.f;
} @end

以下是核心代码:

绘制播放音乐时的音波图形的View的更多相关文章

  1. Android播放音乐时跳动的屏谱demo

    Android实现播放音频时的跳动频谱,并实现可以调节的均衡器. Main.java package com.wjq.audiofx; import android.app.Activity; imp ...

  2. 关于Windows 8使用WMP播放音乐时WUDFHost跑CPU和硬盘的问题解决

    Windows 8使用Windows Media Player播放音乐的时候.事实上有一个这种情况,WMP和某个什么名字看起来非常屌的进程跑CPU非常高,这个跑非常高视你插入的SD卡内的文件数或者移动 ...

  3. Linux版网易云音乐播放音乐时无限显示“网络错误”的解决办法

    安装 gstreamer0.10-plugins-good debian类系统: -plugins-good

  4. 【分享】4412开发板ubuntu 12.0.4播放音乐没有声音解决方法

    转自迅为论坛:http://bbs.topeetboard.com 准备工作 1.下载 vim 在命令行上输入 apt-get install vim 下载 vim 2.输入 vim /etc/hos ...

  5. android 播放音乐-进度条

    今天学渣研究了一下使用MediaPlayer播放音乐时加入进度条,进度条如今用的是android自带的seekbar,后期会跟换UI的,在之前可以播放音乐的基础上,如今加入的主要功能有两个: 1实时显 ...

  6. MUI---IOS切换到后台继续播放音乐

    应用切换到后台继续音乐播放HBuilder默认生成的应用在iOS是不支持后台音乐播放的,当应用切换到后台时音乐将暂停播放,下次切换到前台继续播放.如果要支持应用切换到后台后继续播放音乐功能需要进行额外 ...

  7. Inno调用dll --- 实现背景播放音乐

    Inno 播放音乐可以调用系统api函数mciSendString来实现,而mciSendString函数存在C:\Windows\System32\winmm.dll中,因此最终只要成功从该dll文 ...

  8. iOS开发系列--扩展--播放音乐库中的音乐

    众所周知音乐是iOS的重要组成播放,无论是iPod.iTouch.iPhone还是iPad都可以在iTunes购买音乐或添加本地音乐到音乐 库中同步到你的iOS设备.在MediaPlayer.fram ...

  9. iPhone播放音乐

    来源:http://blog.csdn.net/htttw/article/details/7842295 iPhone播放音乐 今天我们简要介绍如何在iPhone中播放音乐: 强烈建议你参考官方文档 ...

随机推荐

  1. 微信公共平台注册 bug: 验证码不应该输入后,就立即检查其有效性

    本文链接: https://www.cnblogs.com/hchengmx/p/10793037.html 刚刚想注册个微信公众号,就发现了这个问题,在这里记录一下. 已经发到testhome了,链 ...

  2. (转)Apache和Nginx运行原理解析

    Apache和Nginx运行原理解析 原文:https://www.server110.com/nginx/201402/6543.html Web服务器 Web服务器也称为WWW(WORLD WID ...

  3. (转)linux内存源码分析 - 内存回收(整体流程)

    http://www.cnblogs.com/tolimit/p/5435068.html------------linux内存源码分析 - 内存回收(整体流程) 概述 当linux系统内存压力就大时 ...

  4. JDBC(2)-使用statment接口实现增删改操作

    1.Statement接口引入 作用:用于执行静态SQL语句并返回它所生成结果的对象. int executeUpdate(String sql) :执行给定SQL语句,该语句可能为insert.up ...

  5. Object-c 中的数据类型

    导航:  基本类型  ID 对象类型常见的有 对象类型 -NSLog -NSNumber -NSString和NSMutableString -NSArray和NSMutableArray -NSSe ...

  6. 【ExtJS】关于Component生命周期

    很久以前就学习过extjs的组件生命周期,很久之后,再回头看一看,又增加好多新的认识. extjs组件生命周期大体分为3个阶段:初始化.渲染.销毁. 第一阶段:初始化 初始化工作开始于组件的诞生,所有 ...

  7. 获取单个checkbox选中项

    1.获取单个checkbox选中项(三种写法)$("input:checkbox:checked").val()或者$("input:[type='checkbox']: ...

  8. js&&jQuery实现省市区三级联动

    代码参考了:https://codepen.io/anon/pen/WzyNQB;根据自己的需要修改了一下,挂个出处 1.前端页面代码 <html> <head> <me ...

  9. C#语言-07.文件操作

    a. 文件操作:适用于相对简单的数据保存 i. 读写文件的步骤: . 创建文件流 . 创建读写器 . 读写文件 . 关闭读写器 . 关闭文件流 ii. FileStream(文件流),它主要用于读写文 ...

  10. java 并发(五)---AbstractQueuedSynchronizer(3)

           文章代码分析和部分图片来自参考文章 问题 : CountDownLatch  和 CyclicBarrier 的区别 认识 CountDownLatch 分析这个类,首先了解一下它所可以 ...