如何在自定义键盘中播放键盘点击声音? [英] How to play keyboard click sound in custom keyboard?
问题描述
我用 UIView
创建了自定义键盘。
然而我没有听到键盘的点击声。
所以我试过下面的代码。但我听不到任何事。
如何播放键盘点击声音?
I had created custom keyboard with UIView
.
However I didn't hear click sound of keyboard.
So I tried following codes.But I can't hear anythings.
How can I play that keyboard click sound?
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"Tock"
ofType:@"aiff"]];
AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[click setVolume:0.15f];
[click play];
也尝试了下一个。
AudioServicesPlaySystemSound(0x450);
我如何?
推荐答案
尝试这样:
[[UIDevice currentDevice] playInputClick];
请注意
使用此方法播放标准系统键盘的点击响应
给用户点击自定义输入或键盘附件视图。 A
只有在用户在设置>
声音中启用键盘点击,并且只有在输入视图本身已启用并可见时才会点击。
Use this method to play the standard system keyboard click in response to a user tapping in a custom input or keyboard accessory view. A click plays only if the user has enabled keyboard clicks in Settings > Sounds, and only if the input view is itself enabled and visible.
要为输入点击启用自定义输入或辅助视图,请执行
以下两个步骤:
To enable a custom input or accessory view for input clicks, perform the following two steps:
在输入视图类中采用UIInputViewAudioFeedback协议。
实现enableInputClicksWhenVisible委托方法返回
YES。
Adopt the UIInputViewAudioFeedback protocol in your input view class. Implement the enableInputClicksWhenVisible delegate method to return YES.
这篇关于如何在自定义键盘中播放键盘点击声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!