绘制播放音乐时的音波图形的View
绘制播放音乐时的音波图形的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的更多相关文章
- Android播放音乐时跳动的屏谱demo
Android实现播放音频时的跳动频谱,并实现可以调节的均衡器. Main.java package com.wjq.audiofx; import android.app.Activity; imp ...
- 关于Windows 8使用WMP播放音乐时WUDFHost跑CPU和硬盘的问题解决
Windows 8使用Windows Media Player播放音乐的时候.事实上有一个这种情况,WMP和某个什么名字看起来非常屌的进程跑CPU非常高,这个跑非常高视你插入的SD卡内的文件数或者移动 ...
- Linux版网易云音乐播放音乐时无限显示“网络错误”的解决办法
安装 gstreamer0.10-plugins-good debian类系统: -plugins-good
- 【分享】4412开发板ubuntu 12.0.4播放音乐没有声音解决方法
转自迅为论坛:http://bbs.topeetboard.com 准备工作 1.下载 vim 在命令行上输入 apt-get install vim 下载 vim 2.输入 vim /etc/hos ...
- android 播放音乐-进度条
今天学渣研究了一下使用MediaPlayer播放音乐时加入进度条,进度条如今用的是android自带的seekbar,后期会跟换UI的,在之前可以播放音乐的基础上,如今加入的主要功能有两个: 1实时显 ...
- MUI---IOS切换到后台继续播放音乐
应用切换到后台继续音乐播放HBuilder默认生成的应用在iOS是不支持后台音乐播放的,当应用切换到后台时音乐将暂停播放,下次切换到前台继续播放.如果要支持应用切换到后台后继续播放音乐功能需要进行额外 ...
- Inno调用dll --- 实现背景播放音乐
Inno 播放音乐可以调用系统api函数mciSendString来实现,而mciSendString函数存在C:\Windows\System32\winmm.dll中,因此最终只要成功从该dll文 ...
- iOS开发系列--扩展--播放音乐库中的音乐
众所周知音乐是iOS的重要组成播放,无论是iPod.iTouch.iPhone还是iPad都可以在iTunes购买音乐或添加本地音乐到音乐 库中同步到你的iOS设备.在MediaPlayer.fram ...
- iPhone播放音乐
来源:http://blog.csdn.net/htttw/article/details/7842295 iPhone播放音乐 今天我们简要介绍如何在iPhone中播放音乐: 强烈建议你参考官方文档 ...
随机推荐
- VSCode快捷键整理
shift+option+command+上下方向键 在上下方向增加或减少光标 shift+option+上下方向件 在复制当前行到下方或上方 位置跟方向键相反 shift+command+k 删除当 ...
- nodejs 并发控制
1.用 eventproxy 实现控制并发: var EventProxy = require('eventproxy'); const most = 5;//并发数5 var urllist = [ ...
- 关于ASP.NET MVC+Repository+Service架构的一些思考
看了一些ASP.NET MVC开源项目后的一些想法,关于ASP.NET MVC+Repository+Service架构的一些思考 最近在学习ASP.NET MVC 2.0的一些开源项目,发现这些项目 ...
- Git学习系列之Git 的缺点有哪些?
不多说,直接上干货 前面,谈及了 Git学习系列之Git 的优势有哪些? 缺点: (1)资料少(起码中文资料很少). (2)学习周期相对而言比较长. (3)不符合常规思维. (4)代码保密性差,一旦开 ...
- Git学习系列之Git是什么?
前言 现在主流IDE里,都集成git了. https://git-scm.com/docs 史上最浅显易懂的Git教程! 为什么要编写这个教程?因为我在学习Git的过程中,买过书,也在网上Google ...
- 九度oj 1468 Sharing 2012年浙江大学计算机及软件工程研究生机试真题
题目1468:Sharing 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2687 解决:550 题目描述: To store English words, one method is ...
- SpringBoot | 第三十六章:集成多CacheManager
前言 今天有网友咨询了一个问题:如何在一个工程中使用多种缓存进行差异化缓存,即实现多个cacheManager灵活切换.原来没有遇见这种场景,今天下班抽空试了下,以下就把如何实现的简单记录下. 一点知 ...
- 记一次bug修复过程
我的建议,究竟有谁会看,以我的位置,到底能推动到哪一层可行性,可能性 问题:用户的数据丢失了.以为是修改操作 有bug,但查看了后端接口和前端校验,都没有发现问题.但是input数据没有日志[日志级别 ...
- window.open()被浏览器拦截问题汇总
一.问题描述 最近在做项目的时候碰到了使用window.open被浏览器拦截的情况,虽然在自己的环境可以对页面进行放行,但是对用户来说,不能要求用户都来通过拦截.何况当出现拦截时,很多用户根本不知道发 ...
- Spring相关概念的理解理解
spring 框架的优点是一个轻量级比较简单易学的框架,实际使用中的有点优点有哪些呢!1.降低了组件之间的耦合性 ,实现了软件各层之间的解耦 2.可以使用容易提供的众多服务,如事务管理,消息服务等 3 ...