实现键盘咔嗒声,丢失 [英] Implement a keyboard click sound, lost
问题描述
本网站上的每个人对我的iOS编程都非常有帮助,但我遇到了一个非常简单的功能。我已经找到了关于按钮触摸时实现工厂键盘点击声音的Apples文档,但我没有得到的是创建一个UIView的小部分部分。我有一个非常基本的计算器,按钮由标准的Round Rect制成,我想制作简单的咔嗒声。所以Apple说:采用UIInputViewAudioFeedback协议
执行以下三个步骤来采用UIInputViewAudioFeedback协议:
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. 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. 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. So Apple says:Adopting the UIInputViewAudioFeedback Protocol Perform the following three steps to adopt the UIInputViewAudioFeedback protocol:
在你的Xcode项目中,创建一个UIView类的子类。在头文件中,指示子类符合UIInputViewAudioFeedback协议,如下所示:
@interface KeyboardAccessoryView:UIView {
}
In your Xcode project, create a subclass of the UIView class. In the header file, indicate that the subclass conforms to the UIInputViewAudioFeedback protocol, as follows: @interface KeyboardAccessoryView : UIView { }
现在我我使用标准的UIViewController绑定到xib与我的所有按钮。我是:创建新文件,将其命名为UIView的子类,JUST所以我可以实现这个声音?这对我来说没有意义,如果这是非常业余的东西我道歉,但我从许多不同的地方学习。在此先感谢。
Now I am using the standard UIViewController tied to a xib with all my buttons. Am i to: Create New File, name it as a subclass of UIView, JUST so i can implement this sound? 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.
推荐答案
您必须将自定义输入视图设置为 inputView
应该是第一个响应者的对象的属性(例如, UITextField
实例),以及 inputView
(您的自定义输入视图)必须符合 UIInputViewAudioFeedback
协议。并实际发出咔嗒声: [[UIDevice currentDevice] playinputClick]
。
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. And to actually play a click sound: [[UIDevice currentDevice] playinputClick]
.
例如:
@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;
这篇关于实现键盘咔嗒声,丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!