星空网 > 软件开发 > 操作系统

【代码笔记】钢琴小游戏

一,效果图。

【代码笔记】钢琴小游戏images/loading.gif' data-original="http://images2015.cnblogs.com/blog/337518/201510/337518-20151016100456554-2042807486.jpg" width="218" height="400" />

二,工程图。

【代码笔记】钢琴小游戏

三,代码。

RootViewController.h

【代码笔记】钢琴小游戏
#import <UIKit/UIKit.h>//加入头文件#import <AudioToolbox/AudioToolbox.h>@interface RootViewController : UIViewController{  NSString *soundFile;}@end
【代码笔记】钢琴小游戏

 

RootViewController.m

【代码笔记】钢琴小游戏
#import "RootViewController.h"@interface RootViewController ()@end@implementation RootViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  if (self) {    // Custom initialization  }  return self;}- (void)viewDidLoad{  [super viewDidLoad];  // Do any additional setup after loading the view.    //初始化界面  [self addView];}#pragma -mark -fucntions-(void)addView{  NSArray *titleArray=[[NSArray alloc]initWithObjects:@"DO",@"RE",@"MI",@"FA",@"SO",@"LA",@"SI",@"C",@"D",@"E",@"F",@"G", nil];    for (int i=0; i<12; i++) {    UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(50, 80+30*i, 70, 20)];    [button setTitle:[titleArray objectAtIndex:i] forState:UIControlStateNormal];    [button addTarget:self action:@selector(doClickAction:) forControlEvents:UIControlEventTouchUpInside];    button.tag=i;    button.backgroundColor=[UIColor redColor];    [self.view addSubview:button];  }}-(void)playSound:(NSString*)soundKey{    NSString *path = [NSString stringWithFormat:@"%@%@",[[NSBundle mainBundle] resourcePath],soundKey];  SystemSoundID soundID;  NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];  AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);  AudioServicesPlaySystemSound(soundID);  }#pragma -makr -doClickActions-(void)doClickAction:(UIButton *)btn{  NSLog(@"---doClickActions--");  NSLog(@"--btn.tag---%ld",btn.tag);    if (btn.tag==0) {    soundFile = [NSString stringWithFormat:@"/001.mp3"];    [self playSound: soundFile];  }else if (btn.tag==1){    soundFile = [NSString stringWithFormat:@"/002.mp3"];    [self playSound: soundFile];  }else if (btn.tag==2){    soundFile = [NSString stringWithFormat:@"/003.mp3"];    [self playSound: soundFile];  }else if (btn.tag==3){    soundFile = [NSString stringWithFormat:@"/004.mp3"];    [self playSound: soundFile];  }else if (btn.tag==4){    soundFile = [NSString stringWithFormat:@"/005.mp3"];    [self playSound: soundFile];  }else if (btn.tag==5){    soundFile = [NSString stringWithFormat:@"/006.mp3"];    [self playSound: soundFile];  }else if (btn.tag==6){    soundFile = [NSString stringWithFormat:@"/007.mp3"];    [self playSound: soundFile];  }else if (btn.tag==7){    soundFile = [NSString stringWithFormat:@"/C.mp3"];    [self playSound: soundFile];  }else if (btn.tag==8){    soundFile = [NSString stringWithFormat:@"/D.mp3"];    [self playSound: soundFile];  }else if (btn.tag==9){    soundFile = [NSString stringWithFormat:@"/E.mp3"];    [self playSound: soundFile];  }else if (btn.tag==10){    soundFile = [NSString stringWithFormat:@"/F.mp3"];    [self playSound: soundFile];  }else if (btn.tag==11){    soundFile = [NSString stringWithFormat:@"/G.mp3"];    [self playSound: soundFile];  }}- (void)didReceiveMemoryWarning{  [super didReceiveMemoryWarning];  // Dispose of any resources that can be recreated.}
【代码笔记】钢琴小游戏

 

 


 

原标题:【代码笔记】钢琴小游戏

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

跨境电商怎么考核:https://www.goluckyvip.com/tag/36608.html
跨境电商怎么起步:https://www.goluckyvip.com/tag/36609.html
每周精选:https://www.goluckyvip.com/tag/3661.html
跨境电商怎么玩:https://www.goluckyvip.com/tag/36610.html
跨境电商怎么学:https://www.goluckyvip.com/tag/36611.html
跨境电商怎么学习:https://www.goluckyvip.com/tag/36612.html
23点聊电商:新质生产力加速数字贸易发展 卓尔智联集团实现营收利润双增长 :https://www.kjdsnews.com/a/1836411.html
南京浦口都有什么好玩的地方 南京浦口都有什么好玩的地方推荐:https://www.vstour.cn/a/363180.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流