我创建了一个用作自定义一个UICollectionViewController的子类inputAccessoryViewController中UITextView.
https://developer.apple.com/reference/uikit/uiresponder/1621124-inputaccessoryviewcontroller
当您使用playInputClick点击集合视图中的单元格时,我想播放键盘单击声音. https://developer.apple.com/reference/uikit/uidevice/1620050-playinputclick
我无法弄清楚如何在集合视图中使用它.它适用于这样的简单视图使用a的inputAccessoryView属性,UITextView但我不确定在集合视图控制器层次结构中的子类视图,以获得键盘单击声音.
@interface KeyboardClickView : UIView <UIInputViewAudioFeedback>
@end
@implementation KeyboardClickView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if(self)
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[self addGestureRecognizer:tap];
}
return self;
}
- (void)tap:(id)sender
{
[[UIDevice currentDevice] playInputClick];
}
- (BOOL)enableInputClicksWhenVisible
{
return YES;
}
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_inputAccessoryView = [[KeyboardClickView alloc] initWithFrame:CGRectMake(0, 0, 0, 50)];
_inputAccessoryView.backgroundColor = [UIColor redColor];
[[UITextView appearance] setInputAccessoryView:_inputAccessoryView]; …Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试一些示例和检查文档,但我不能让它工作.这是我的代码:
@interface AHMSoudView : UIView <UIInputViewAudioFeedback>
- (void) playClick;
@end
@implementation AHMSoudView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (BOOL) enableInputClicksWhenVisible {
return YES;
}
- (void) playClick {
[[UIDevice currentDevice] playInputClick];
}
@end
Run Code Online (Sandbox Code Playgroud)
在故事板中,我将视图设置为我的AHMSoundView.在控制器中,我有:
- (IBAction)keypadTouchDown:(id)sender {
[((AHMSoudView *)self.view) playClick];
}
Run Code Online (Sandbox Code Playgroud)
但没有任何反应.我究竟做错了什么?
在界面构建器中,"可访问性"下的UIButton属性显示为"播放声音".
任何人都可以解释这是什么.实际上我正在制作一个应用程序,它在每次按钮点击播放声音,我可以禁用设置屏幕的声音.UIButton的这个属性能帮助我吗?
谢谢