简体   繁体   English

实施键盘咔嗒声,丢失

[英]Implement a keyboard click sound, lost

Everyone on this site has been very helpful on my schooling of iOS programming, but I've run into a brick wall with a very simple feature. 这个站点上的每个人对我的iOS编程学习都非常有帮助,但是我碰到了一个非常简单的功能。 I've found Apples documentation on implementing the factory keyboard click sound upon a button touch, but what Im not getting is the "creating a sub lass of UIView" part. 我已经找到了有关实现按键时实现工厂键盘点击声音的Apple文档,但是我没有得到的是“创建UIView的子集”部分。 I have a very basic calculator that I've built, the buttons are made of standard Round Rect's that I want to make the simple click sound. 我有一个非常基本的计算器,按钮由标准的Round Rect制成,我想发出简单的点击声音。 So Apple says:Adopting the UIInputViewAudioFeedback Protocol Perform the following three steps to adopt the UIInputViewAudioFeedback protocol: 因此苹果说:采用UIInputViewAudioFeedback协议执行以下三个步骤以采用UIInputViewAudioFeedback协议:

In your Xcode project, create a subclass of the UIView class. 在您的Xcode项目中,创建UIView类的子类。 In the header file, indicate that the subclass conforms to the UIInputViewAudioFeedback protocol, as follows: @interface KeyboardAccessoryView : UIView { } 在头文件中,指示子类符合UIInputViewAudioFeedback协议,如下所示:@interface KeyboardAccessoryView:UIView {}

Now I am using the standard UIViewController tied to a xib with all my buttons. 现在,我使用所有按钮将标准UIViewController绑定到xib。 Am i to: Create New File, name it as a subclass of UIView, JUST so i can implement this sound? 我是否要:创建新文件,将其命名为UIView的子类,以便我可以实现这种声音? That doesn't make sense to me, and if this is really amateur stuff I apologize, but I'm learning from many different places. 这对我来说毫无意义,如果这真的是业余的话,我表示歉意,但是我正在从许多不同的地方学习。 Thanks in advance. 提前致谢。

You have to set your custom input view as the inputView property of the object that is supposed to be the first responder (For example, a UITextField instance), and the inputView (your custom input view) must conform to the UIInputViewAudioFeedback protocol. 您必须将自定义输入视图设置为应该是第一响应者的对象的inputView属性(例如, UITextField实例),并且inputView (您的自定义输入视图)必须符合UIInputViewAudioFeedback协议。 And to actually play a click sound: [[UIDevice currentDevice] playinputClick] . 并实际播放点击声音: [[UIDevice currentDevice] playinputClick]

For example: 例如:

@interface MyCalculatorDisplay : UIView
// ...
@end

@interface MyCustomKeyboard : UIView <UIInputViewAudioFeedback>
// ...
@end

// Then, somewhere in your controller:

MyCustomKeyboard *keyboard = [MyCustomKeyboard new];

MyCalculatorDisplay *display = [MyCalculatorDisplay new];

display.inputView = keyboard;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM