iOS开发--QQ音乐练习,歌词的展示,歌词的滚动,歌词的颜色变化
一.歌词的展示 -- 首先歌词是在scrollView上,scrollView的大小是两个屏幕的宽度

- scrollView滚动修改透明度的代码

- 自定义展示歌词的view,继承自UIScrollView,向外界提供一个歌词文件名的属性
/** 歌词文件的名字 */
@property(nonatomic,copy) NSString *lrcFileName;
重写setter,解析歌词,通过歌词的工具类获得模型集合

- 歌词工具类的实现
#import "ChaosLrcTool.h"
#import "ChaosLrc.h" @implementation ChaosLrcTool
+ (NSArray *)lrcToolWithLrcName:(NSString *)lrcname
{
// 1.获取文件路径
NSString *lrcPath = [[NSBundle mainBundle] pathForResource:lrcname ofType:nil];
// 2.加载文件内容
NSString *lrcString = [NSString stringWithContentsOfFile:lrcPath encoding:NSUTF8StringEncoding error:nil];
// 3.切割字符串
NSArray *lrcLines = [lrcString componentsSeparatedByString:@"\n"];
// 4.遍历集合,转换成歌词模型
NSMutableArray *arr = [NSMutableArray array];
for (NSString *lrcLineString in lrcLines) {
/*
[ti:简单爱]
[ar:周杰伦]
[al:范特西]
*/
// 5.跳过指定行
if ([lrcLineString hasPrefix:@"[ti"] || [lrcLineString hasPrefix:@"[ar"] || [lrcLineString hasPrefix:@"[al"] || ![lrcLineString hasPrefix:@"["]) {
continue;
}
ChaosLrc *lrc = [ChaosLrc lrcWithLrcLine:lrcLineString];
[arr addObject:lrc];
}
return arr;
}
@end - 歌词解析完毕后,根据歌词模型集合来实现tableView(歌词用tableView来显示)的数据源方法

二.歌词的滚动
- 歌词的滚动由每一句的时间来决定,自定义的歌词的view需要外界不停的提供歌曲播放的时间,自己来判断并滚动显示对应的歌词.所以自定义的歌词View需要向外界提供一个时间属性,重写时间属性来实现歌词滚动
#pragma mark - 歌词滚动
// 重写time的setter
- (void)setCurrentTime:(NSTimeInterval)currentTime
{
_currentTime = currentTime;
// 遍历歌词,找到对应时间应该显示的歌词模型
for (int i = ; i < self.lrcList.count; i++) {
// 当前的歌词
ChaosLrc *lrc = self.lrcList[i];
NSInteger next = i + ;
// 下一句歌词
ChaosLrc *nextLrc;
if (next < self.lrcList.count) {
nextLrc = self.lrcList[next];
}
if (self.currentLrcIndex != i && currentTime >= lrc.time && currentTime < nextLrc.time) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:];
NSIndexPath *previousIndexPath = [NSIndexPath indexPathForRow:self.currentLrcIndex inSection:];
// 记录当前行
self.currentLrcIndex = i;
// 满足条件,tableview滚动
[self.lrcView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
// 刷新上一行,字体还原
[self.lrcView reloadRowsAtIndexPaths:@[previousIndexPath] withRowAnimation:UITableViewRowAnimationNone];
// 刷新当前行,字体变大
[self.lrcView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
// 当前歌词的label的进度
if (self.currentLrcIndex == i) { // 获取当前的cell
NSIndexPath *currentIndexPath = [NSIndexPath indexPathForRow:i inSection:];
ChaosLrcCell *currentCell = [self.lrcView cellForRowAtIndexPath:currentIndexPath];
CGFloat totalTime = nextLrc.time - lrc.time; // 当前歌词总时间
CGFloat progressTime = currentTime - lrc.time; // 当前歌词已经走过了多长时间
currentCell.lrcLabel.progress = progressTime / totalTime; // 主页的label
self.mainLabel.text = lrc.text;
self.mainLabel.progress = currentCell.lrcLabel.progress;
}
}
} - 外界给歌词的View提供时间就不是每一秒提供一次那么简单了,外界需要更牛逼的定时器
- 播放的时候添加定时器

- 定时器的方法中实现给歌词的view提供的时间属性赋值

- 播放的时候添加定时器
三.歌词的颜色变化 -- 画上去的(自定义cell中的显示歌词的label,label需要外界提供一个进度值,自己内部根据进度值来画)

- 自定义label的实现
#import "ChaosLabel.h" @implementation ChaosLabel - (void)setProgress:(CGFloat)progress
{
_progress = progress;
// 重绘
[self setNeedsDisplay];
} - (void)drawRect:(CGRect)rect { [super drawRect:rect]; // 1.获取需要画的区域
CGRect fillRect = CGRectMake(, , self.bounds.size.width * self.progress, self.bounds.size.height);
// 2.选择颜色
[[UIColor yellowColor] set];
// 3.添加区域开始画图
// UIRectFill(fillRect);
UIRectFillUsingBlendMode(fillRect, kCGBlendModeSourceIn);
} @end 外部进度值的计算

iOS开发--QQ音乐练习,歌词的展示,歌词的滚动,歌词的颜色变化的更多相关文章
- iOS开发--QQ音乐练习,后台播放和锁屏界面
一.设置后台播放 首先允许程序后台播放 代码实现 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOpti ...
- iOS开发--QQ音乐练习,旋转动画的实现,音乐工具类的封装,定时器的使用技巧,SliderBar的事件处理
一.旋转动画的实现 二.音乐工具类的封装 -- 返回所有歌曲,返回当前播放歌曲,设置当前播放歌曲,返回下一首歌曲,返回上一首歌曲方法的实现 头文件 .m文件 #import "ChaosMu ...
- 10、 在QQ音乐中爬取某首歌曲的歌词
需求就是把关卡内的代码稍作修改,将周杰伦前五页歌曲的歌词都爬取下来,结果就是全部展示打印出来. URL https://y.qq.com/portal/search.html#p ...
- iOS开发 QQ粘性动画效果
QQ(iOS)客户端的粘性动画效果 时间 2016-02-17 16:50:00 博客园精华区 原文 http://www.cnblogs.com/ziyi--caolu/p/5195615.ht ...
- IOS 开发qq登陆界面
// // ViewController.m // QQUI_bydfg // // Created by Kevin_dfg on 16/4/15. // Copyright © 2016年 ...
- iOS开发QQ空间半透明效果的实现
//1.首先我们可以确定的是cell的半透明, /* white The grayscale value of the color object, specified as a value from ...
- iOS开发所有KeyboardType与图片对应展示
1.UIKeyboardTypeAlphabet 2.UIKeyboardTypeASCIICapable 3.UIKeyboardTypeDecimalPad 4.UIKeyboardTypeDe ...
- iOS开发-- 如何让 UITableView 的 headerView跟随 cell一起滚动
在我们利用 UITableView 展示我们的内容的时候,我需要在顶部放一个不同于一般的cell的 界面,这个界面比较独特. 1. 所以我就把它 作为一个section的 headerView. 也就 ...
- iOS开发技巧(系列十八:扩展UIColor,支持十六进制颜色设置)
新建一个Category,命名为UIColor+Hex,表示UIColor支持十六进制Hex颜色设置. UIColor+Hex.h文件, #import <UIKit/UIKit.h> # ...
随机推荐
- 初探网络编程--TCP套接字编程演示
今天看了一下<计算机网络:自顶向下方法>,也就是计算机网络的教材的应用层一章,决定实现以下后面的Java C/S应用程序的例子,用来演示TCP和UDP套接字编程. 程序流程如下: 1.一台 ...
- BestCoder Round #87 1003 LCIS[序列DP]
LCIS Accepts: 109 Submissions: 775 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65 ...
- 终于可以在centos下使用QQ啦!
电脑装了centos 6.4操作系统,一直无法使用QQ,在centos中文论坛看到一篇介绍安装qq的文章,依样画葫芦,终于成功了1.下载QQ2012软件安装包,我给大家准备好了下载地址 [root@b ...
- 批处理文件指定jre路径启动java桌面应用程序
应用场景: 我开发了一个应用程序,并连同jre一起刻成光盘,提供给用户,用户直接双击批处理文件即可运行,而不需要自己额外装jre. 目录组织结构如下: client |-images |-jre |- ...
- 基于tiny6410的madplay播放器的移植
在移植madplay之前需要先将所需要的库移植到开发板的文件系统中. 现在每个解压后的文件夹中创建一个文件夹 zlib-1.1.4.tar.gz 解压:tar xvzf zlib-1.1.4.tar ...
- vijos1037搭建双塔(一维背包问题)
描述 2001年9月11日,一场突发的灾难将纽约世界贸易中心大厦夷为平地,Mr. F曾亲眼目睹了这次灾难.为了纪念“9?11”事件,Mr. F决定自己用水晶来搭建一座双塔. Mr. F有N块水晶,每块 ...
- html5游戏-追踪算法
追踪算法的原理:目标位置 - 当前位置 / 速度,即: dx = targetX - currentX / speed, dy = targetY - currentY / speed var get ...
- 规范化注释 VVDocumenter的使用方法
很多时候,为了快速开发,很多的技术文档都是能省则省,这个时候注释就变得异常重要,但是每次都要手动输入规范化的注释,着实也麻烦,但有了VVDocumenter,规范化的注释,主需要输入三个斜线“///” ...
- C# 发送邮件,QQ企业邮箱测试成功
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...
- vue 滚动加载
<template> <div class="wraper" @scroll="onScroll($event)"> <div c ...