pickview加载图片和声音
2013-04-16 10:30
141 查看
pickview加载图片和声音
#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h>
//#import <AudioToolbox/AudioServices.h>
@interfaceViewController ()
@end
@implementation ViewController
@synthesize column1;
@synthesize column2;
@synthesize column3;
@synthesize column4;
@synthesize label;
@synthesize picker;
@synthesize selectButton;
-(void)spin
{
BOOL win=NO;
int numInRow=1;
int lastVal=-1;
for (int i=0; i<5; i++) {
int newValue=random()%[self.column1count];
if (newValue==lastVal) {
numInRow++;
}
else
{
numInRow=1;
}
lastVal=newValue;
[picker selectRow:newValueinComponent:i
animated:YES];
[pickerreloadComponent:i];
if (numInRow>=3) {
win=YES;
}
}
selectButton.hidden=YES;
NSString *path=[[NSBundlemainBundle]pathForResource:@"crunch"ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridgeCFURLRef)[NSURLfileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
if (win) {
ClickIndex++;
[selfperformSelector:@selector(playWinSound)withObject:nilafterDelay:.5];
}
else
{
ClickIndex++;
[selfperformSelector:@selector(showButton)withObject:nilafterDelay:.5];
label.text=[[NSStringalloc]initWithFormat:
@"第%d次",ClickIndex ];
}
}
-(void) showButton
{
selectButton.hidden=NO;
}
-(void) playWinSound
{
NSString *path=[[NSBundlemainBundle]pathForResource:@"win"ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridgeCFURLRef)[NSURLfileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
label.text=[[NSStringalloc ]initWithFormat:
@"You WIN,play times is %d",ClickIndex ];
[selfperformSelector:@selector(showButton)withObject:nilafterDelay:1.5];
ClickIndex=0;
}
- (void)viewDidLoad
{
self.picker.delegate=self;
self.picker.dataSource=self;
ClickIndex=0;
UIImage *seven=[UIImage imageNamed:@"seven.png"];
UIImage *bar=[UIImage imageNamed:@"bar.png"];
UIImage *crown=[UIImage imageNamed:@"crown.png"];
UIImage *lemon=[UIImage imageNamed:@"lemon.png"];
UIImage *apple=[UIImage imageNamed:@"apple.png"];
UIImage *cherry=[UIImage imageNamed:@"cherry.png"];
for (int i=1; i<=5; i++) {
UIImageView *sevenView=[[UIImageView alloc]initWithImage:seven];
UIImageView *barView=[[UIImageView alloc]initWithImage:bar];
UIImageView *crownView=[[UIImageView alloc]initWithImage:crown];
UIImageView *lemonView=[[UIImageView alloc]initWithImage:lemon];
UIImageView *appleView=[[UIImageView alloc]initWithImage:apple];
UIImageView *cherryView=[[UIImageView
alloc] initWithImage:cherry];
NSArray *imageViewArray=[[NSArray alloc]initWithObjects:sevenView,
barView,crownView,lemonView,appleView,cherryView,nil];
NSString *fieldName=
[[NSStringalloc] initWithFormat:@"column%d",i];
[self setValue:imageViewArrayforKey:fieldName];
//[fieldName release];
}
srandom(time(NULL));
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark -
#pragma Picker Data Source Methods
-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return5;
}
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [self.column1count];
}
#pragma mark Picker Delegate Methods
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
NSString *arrayName=[[NSString alloc]initWithFormat:@"column%d",component+1];
NSArray *array=[self valueForKey:arrayName];
return [array objectAtIndex:row];
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h>
//#import <AudioToolbox/AudioServices.h>
@interfaceViewController ()
@end
@implementation ViewController
@synthesize column1;
@synthesize column2;
@synthesize column3;
@synthesize column4;
@synthesize label;
@synthesize picker;
@synthesize selectButton;
-(void)spin
{
BOOL win=NO;
int numInRow=1;
int lastVal=-1;
for (int i=0; i<5; i++) {
int newValue=random()%[self.column1count];
if (newValue==lastVal) {
numInRow++;
}
else
{
numInRow=1;
}
lastVal=newValue;
[picker selectRow:newValueinComponent:i
animated:YES];
[pickerreloadComponent:i];
if (numInRow>=3) {
win=YES;
}
}
selectButton.hidden=YES;
NSString *path=[[NSBundlemainBundle]pathForResource:@"crunch"ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridgeCFURLRef)[NSURLfileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
if (win) {
ClickIndex++;
[selfperformSelector:@selector(playWinSound)withObject:nilafterDelay:.5];
}
else
{
ClickIndex++;
[selfperformSelector:@selector(showButton)withObject:nilafterDelay:.5];
label.text=[[NSStringalloc]initWithFormat:
@"第%d次",ClickIndex ];
}
}
-(void) showButton
{
selectButton.hidden=NO;
}
-(void) playWinSound
{
NSString *path=[[NSBundlemainBundle]pathForResource:@"win"ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridgeCFURLRef)[NSURLfileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
label.text=[[NSStringalloc ]initWithFormat:
@"You WIN,play times is %d",ClickIndex ];
[selfperformSelector:@selector(showButton)withObject:nilafterDelay:1.5];
ClickIndex=0;
}
- (void)viewDidLoad
{
self.picker.delegate=self;
self.picker.dataSource=self;
ClickIndex=0;
UIImage *seven=[UIImage imageNamed:@"seven.png"];
UIImage *bar=[UIImage imageNamed:@"bar.png"];
UIImage *crown=[UIImage imageNamed:@"crown.png"];
UIImage *lemon=[UIImage imageNamed:@"lemon.png"];
UIImage *apple=[UIImage imageNamed:@"apple.png"];
UIImage *cherry=[UIImage imageNamed:@"cherry.png"];
for (int i=1; i<=5; i++) {
UIImageView *sevenView=[[UIImageView alloc]initWithImage:seven];
UIImageView *barView=[[UIImageView alloc]initWithImage:bar];
UIImageView *crownView=[[UIImageView alloc]initWithImage:crown];
UIImageView *lemonView=[[UIImageView alloc]initWithImage:lemon];
UIImageView *appleView=[[UIImageView alloc]initWithImage:apple];
UIImageView *cherryView=[[UIImageView
alloc] initWithImage:cherry];
NSArray *imageViewArray=[[NSArray alloc]initWithObjects:sevenView,
barView,crownView,lemonView,appleView,cherryView,nil];
NSString *fieldName=
[[NSStringalloc] initWithFormat:@"column%d",i];
[self setValue:imageViewArrayforKey:fieldName];
//[fieldName release];
}
srandom(time(NULL));
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark -
#pragma Picker Data Source Methods
-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return5;
}
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [self.column1count];
}
#pragma mark Picker Delegate Methods
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
NSString *arrayName=[[NSString alloc]initWithFormat:@"column%d",component+1];
NSArray *array=[self valueForKey:arrayName];
return [array objectAtIndex:row];
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- Android中WebView加载Html中的图片添加点击事件
- Android中Recyclerview使用13----实现瀑布流遇到的各种问题(item移动,加载更多图片闪烁,以及定制各种类型Header和Footer)
- RecyclerView条目加载图片实现LruCache三级缓存策略,有效避免 OOM , 提升系统流畅性
- RecyclerView的通用适配器,和滚动时不加载图片的封装
- 动态viewpager加载图片
- UITableview性能优化总结—图片加载、行高返回
- 基于universalimageloader实现的图片加载控件BlurImageView
- Android用webView加载h5的页面,h5获取本地的图库中的图片
- 写一个可以使用kingfisher加载图片的轮播器PPTView
- 解决RecyclerView加载图片时复用itemview导致的图片数量错乱问题
- recycleview实现九宫格图片加载不全的问题
- android textView 加载HTML 异步加载网络图片
- Android webview 使用HTTPS时有的图片不能加载
- Android webview加载https网页时http图片无法显示
- 解决RecyclerView中使用UIL加载网络图片,在刷新时出现闪烁问题
- 谷歌官网的Volley网络框架实战②--ImageRequest、ImageLoader、NetworkImageView加载图片
- listView convertView缓存机制 & 异步加载图片 问题剖析
- Android webview加载本地图片
- webview中的img标签加载Android本地的图片
- Glide加载图片遇到的错误:You must not call setTag() on a view Glide is targeting