如何通过UIswtch控制音频声音的开启和关闭
在日期选择器中选择日期时播放点击声音。现在我需要使用 UISWitch 设置我的设置模块以进行控制开和关。 如何将声音控制设置为 uiswitch 。
-(void) switchforSounds:(id)sender
{
if ([sender isOn])
{
[Appdelegate.infoObj playback];
}
else
{
}
}
-(void) playback
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"click" ofType:@"caf"];
if (path)
{
NSURL *url = [NSURL fileURLWithPath: path];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID ((CFURLRef)url, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
Playing sound for click sound when date is selected in the date picker. Now i need to set my setting module for control ON and OFF using UISWitch.
How to set my control of sound to uiswitch .
-(void) switchforSounds:(id)sender
{
if ([sender isOn])
{
[Appdelegate.infoObj playback];
}
else
{
}
}
-(void) playback
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"click" ofType:@"caf"];
if (path)
{
NSURL *url = [NSURL fileURLWithPath: path];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID ((CFURLRef)url, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
又好又简单:
如果这不是您想要的,我可以随时修改它。
Nice and easy:
If that wasn't what you were looking for, I can always revise it.
如果问题是如何将 IB 中的开关绑定到您的函数
-(void) switchforSounds:(id)sender
答案是像这样声明它:
- (IBAction) switchforSounds:(id) sender
分别在 .h 和 .m 文件中。右键单击IB中的开关,您将看到它可以响应的所有事件。选择changeValue 事件。单击它附近的钩子并将其拖动到 IB'c 控制器文件中的文件所有者元素。当您离开鼠标时,它应该显示您在控制器类中定义的所有 IBAction 选择器。选择switchforSounds。
完成。
希望我正确理解你的问题。
if the question is how to bind the switch in IB to your function
-(void) switchforSounds:(id)sender
the answer isdeclare it like this:
- (IBAction) switchforSounds:(id) sender
in your .h and .m file respectively.right click on the switch in IB, you will see all events it can respond to. Choose changeValue event. Click in the hook near it and drag to the File's Owner element in your IB'c controller file. When you leave the mouse it's supposed to show you all IBAction selectors you've defined in your controller class. Choose switchforSounds.
Done.
Hopefully i understood your question right.