我想創建一個按鈕,並在觸摸時使其播放聲音。到目前爲止,我可以製作這個按鈕,但是我很難讓它播放聲音。以下是我的:在iOS中以編程方式製作按鈕播放聲音
//loads wav file into SoundID
NSURL *buttonURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"medic_taunts01" ofType:@"wav"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)buttonURL, &SoundID);
//creates button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[scrollview addSubview:button]
//this line is the problem
[button addTarget:self action:@selector(AudioServicesPlaySystemSound((SoundID)) forControlEvents:UIControlEventTouchDown];
由於某些原因,xcode不會讓我直接從按鈕單擊播放聲音。我怎樣才能讓觸摸按鈕播放SoundID?
如果你已經解決這個問題,然後接受正確的答案,以幫助其他人有同樣的問題。 – BhushanVU
@BhushanUparkar同上 – madLokesh