绘制播放音乐时的音波图形的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. 【百度之星2014~复赛 解题报告~正解】The Query on the Tree

    声明 笔者最近意外的发现 笔者的个人网站http://tiankonguse.com/ 的很多文章被其它网站转载,但是转载时未声明文章来源或参考自 http://tiankonguse.com/ 网站 ...

  2. 阿里云API公共参数的获取

    阿里云公共参数API  https://help.aliyun.com/document_detail/50284.html?spm=5176.10695662.1996646101.searchcl ...

  3. ASP.NET能知道的东西

    ASP.NET能知道的东西 获取服务器电脑名: Page.Server.ManchineName 获取用户信息: Page.User 获取客户端电脑名:Page.Request.UserHostNam ...

  4. [转]象棋AI算法(二)

    本文转自:http://blog.csdn.net/u012723995/article/details/47143569 参考文献:http://bbs.blueidea.com/thread-30 ...

  5. Orchard源码分析 - 缓存管理

        ICacheManager  &   ICacheHolder              Orchard缓存管理主要通过 ICacheManager 接口对外提供缓存服务. 其实现类D ...

  6. JRebel - 给IDE安装JRebel插件

    JRebel对于很多人来说已经并不陌生了,一搜一大把. 用过JRebel后发现,这对于Java开发简直不可缺少. 尽管其价格有点春节国庆期间的各种交通费用——打劫! 即使如此也出现了有"分享 ...

  7. node版本的切换(转)

    大量开发者的贡献使Node版本的迭代速度很快,版本很多(横跨0.6到0.11),所以升级Node版本就成为了一个问题.目前有n和nvm这两个工具可以对Node进行无痛升级,本文简单介绍一下二者的使用. ...

  8. Java 线程--实现java.lang.Runnable接口实现线程

    Java线程的第一种实现方式,主要分两步,第一步是继承java.lang.Thread; 第二步是重写run()方法.接下来我们来看Java线程的第二种实现方式,也是分为两步,第一步,写一个类实现ja ...

  9. 4、springboot之全局异常捕获

    1.新建一个springboot项目 添加一个全局异常的类 import org.springframework.web.bind.annotation.ControllerAdvice; impor ...

  10. python打开文件常见错误及解决办法

    打开文件注意事项: 打开文件时需要,填写正确的路径,需要配置与文件相同的编码方式打开位机例如’utf-8‘,需要以特定 的模式打开文件 r, w,r+,w+,rb,wb,a, a+,ab等模式 f.o ...