【发布时间】:2014-03-05 06:55:02
【问题描述】:
我想创建一个按钮,让它在被触摸时播放声音。到目前为止,我可以制作按钮,但我无法让它播放声音。这是我所拥有的:
//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?
【问题讨论】:
-
如果您已解决此问题,请接受正确答案以帮助遇到相同问题的其他人。
-
@BhushanUparkar 同上
标签: ios objective-c audio uikit