iOS开发拓展篇—音频处理(音乐播放器2)

说明:该文主要介绍音乐播放界面的搭建。

一、跳转

1.跳转到音乐播放界面的方法选择
  (1)使用模态跳转(又分为手动的和自动的)
  (2)使用xib并设置跳转
2.两种方法的分析
  可以使用模态的方法,添加一个控制器,让这个控制器和音乐播放控制器类进行关联,脱线,设置标识符且在cell的点击事件中执行segue即可。
  步骤说明:
  (1)在storyboard中新拖入一个控制器,然后设置和playing控制器类相关联。
    
  (2)设置手动跳转
      
  (3)设置segue的标识符
    
  (3)跳转代码处理
    
  不推荐使用模态的原因如下:
    当选中一首音乐跳转到播放界面进行播放后,如果要跳回到音乐列表界面,那么最常见的做法是在音乐播放控制器上添加一个按钮。
    当点击的时候,销毁这个控制器(dismissed)。但是,控制器销毁了那么正在播放的音乐也就随之不在了。
    且由于播放界面控制器的布局是固定的,因此这里选择的方法是使用xib进行创建。
3.选择的方法
  新建一个xib,对应于音乐播放控制器。
  xib的结构如下图所示:
    
 细节:控制器只需要创建一次,因此建议使用懒加载,当然也可是把播放器设置为单例
   

 //
// YYMusicsViewController.m
// #import "YYMusicsViewController.h"
#import "YYMusicModel.h"
#import "MJExtension.h"
#import "YYMusicCell.h"
#import "YYPlayingViewController.h" @interface YYMusicsViewController ()
@property(nonatomic,strong)NSArray *musics;
@property(nonatomic,strong)YYPlayingViewController *playingViewController;
@end @implementation YYMusicsViewController
#pragma mark-懒加载
-(NSArray *)musics
{
if (_musics==nil) {
_musics=[YYMusicModel objectArrayWithFilename:@"Musics.plist"];
}
return _musics;
}
-(YYPlayingViewController *)playingViewController
{
if (_playingViewController==nil) {
_playingViewController=[[YYPlayingViewController alloc]init];
}
return _playingViewController;
}
4.xib的内部细节:
(1)已经实现了约束,用于适配ios6和ios7。
(2)设置音乐名称和歌手的View设置为半透明的,设置方法如下:
  
  设置为30%
  
  注意:不要再storyboard中控件的属性面板上设置透明度(这样的话,这个控件中的子控件也是同样的透明度)。
    不推荐的做法:
     
(3)按钮点击发光
  
(4)设置view隐藏能够节省一些性能。(参考代码)
(5)在切换控制器的过程中,设置窗口不能点击(这样做是为了防止用户多次连续的点击歌曲名会出现的问题)。
 
5.补充:
  项目代码中拖入了UIView的分类,以方便计算frame
 
二、涉及到的代码
在播放控制器的.h文件中提供一个公共对象方法接口
YYPlayingViewController.h文件

 //  YYPlayingViewController.h

 #import <UIKit/UIKit.h>

 @interface YYPlayingViewController : UIViewController
//显示控制器
-(void)show;
@end

YYPlayingViewController.m文件

 //
// YYPlayingViewController.m
// #import "YYPlayingViewController.h" @interface YYPlayingViewController ()
- (IBAction)exit; @end @implementation YYPlayingViewController
#pragma mark-公共方法
-(void)show
{
//1.禁用整个app的点击事件
UIWindow *window=[UIApplication sharedApplication].keyWindow;
window.userInteractionEnabled=NO; //2.添加播放界面
//设置View的大小为覆盖整个窗口
self.view.frame=window.bounds;
//设置view显示
self.view.hidden=NO;
//把View添加到窗口上
[window addSubview:self.view]; //3.使用动画让View显示
self.view.y=self.view.height;
[UIView animateWithDuration:0.25 animations:^{
self.view.y=;
} completion:^(BOOL finished) {
window.userInteractionEnabled=YES;
}];
}
#pragma mark-内部的按钮监听方法
//返回按钮
- (IBAction)exit {
//1.禁用整个app的点击事件
UIWindow *window=[UIApplication sharedApplication].keyWindow;
window.userInteractionEnabled=NO; //2.动画隐藏View
[UIView animateWithDuration:0.25 animations:^{
self.view.y=window.height;
} completion:^(BOOL finished) {
window.userInteractionEnabled=YES;
//设置view隐藏能够节省一些性能
self.view.hidden=YES;
}];
}
@end

cell的点击事件中的处理代码:

 /**
* cell的点击事件
*/
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//取消选中被点击的这行
[tableView deselectRowAtIndexPath:indexPath animated:YES]; //调用公共方法
10 [self.playingViewController show]; // //执行segue跳转
// [self performSegueWithIdentifier:@"music2playing" sender:nil];
}

最新文章

  1. 安装win7的那些事
  2. 【OpenGL】 第一篇 OpenGL概览
  3. Java Hour 41 Maven ( 3 )
  4. JAVA实现word doc docx pdf excel的在线浏览 - 仿百度文库 源码
  5. 手机端的mousedown
  6. Hadoop Compression
  7. C# Where
  8. 不使用模板导出Excel(C#版本)
  9. Adapter基本用法
  10. Service Fabric部署笔记
  11. Error: no override found for &#39;vtkRenderWindow&#39;
  12. GoLand使用
  13. Task任务的屏障机制
  14. python request 库
  15. 一个很初级的错误 Destructor忘记override导致内存泄露
  16. python文件、文件夹操作OS模块
  17. ASP.NET Web API 框架研究 Controller实例的销毁
  18. Intro to Python for Data Science Learning 5 - Packages
  19. Java学习之路(十二):IO流
  20. idea创建maven的web工程

热门文章

  1. Leetcode: Battleships in a Board
  2. c/c++ 数据结构 链表插入数据代码(一)
  3. Scrum 项目7.0
  4. 循环生成sql文件。
  5. 学习Uml开始
  6. SQL批量添加主键脚本
  7. php strrpos()与strripos()函数不同之处在哪里呢
  8. 【转】Struts1.x系列教程(7):Logic标签库
  9. Android 获取全部应用
  10. [问题2014S03] 解答