gpt4 book ai didi

ios - 如何在自定义键盘中播放键盘点击声音?

转载 作者:IT王子 更新时间:2023-10-29 08:17:29 27 4
gpt4 key购买 nike

我用 UIView 创建了自定义键盘。但是,我没有听到键盘的咔嗒声。所以我尝试了以下代码,但我什么也听不到。如何播放键盘敲击声?

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];

注意

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:

Adopt the UIInputViewAudioFeedback protocol in your input view class. Implement the enableInputClicksWhenVisible delegate method to return YES.

关于ios - 如何在自定义键盘中播放键盘点击声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10299021/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com