gpt4 book ai didi

ios - Swift 3 中点击声音实现的自定义数字键盘

转载 作者:行者123 更新时间:2023-11-28 07:46:35 25 4
gpt4 key购买 nike

我有使用 UICollectionView 制作的自定义数字键盘。我在 didSelectItemAt 方法中获取按下的键值。每当调用 didSelectItemAt 方法时,我都希望键盘发出声音。它应该取决于用户的设备设置。

我已经引用了 Apple 开发人员文档,但我无法实现它。医生说:

To enable a custom input or accessory view for input clicks, perform the following two steps: 1. Adopt the UIInputViewAudioFeedback protocol in your input view class. 2. Implement the enableInputClicksWhenVisible delegate method to return true.

我尝试了以下方式:

  1. 创建了 CustomUICollectionView

class CustomUICollectionView: UICollectionView, UIInputViewAudioFeedback {
var enableInputClicksWhenVisible: Bool {
return true
}
}

  1. 在显示数字键盘的 Controller 中声明变量 numberPad。并在 didSelectItemAt 方法中调用了 playInputClick。

@IBOutlet weak var numberPad: CustomUICollectionView!<br/>
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
UIDevice.current.playInputClick()
}

最佳答案

  1. 您需要从符合 UIInputViewAudioFeedback 的 View 类中调用 playInputClick
  2. 符合UIInputViewAudioFeedback 并调用playInputClick 的类需要是文本字段或 TextView 的事件inputView

重构您的代码以满足这些要求,点击将起作用。

关于ios - Swift 3 中点击声音实现的自定义数字键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50829513/

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