gpt4 book ai didi

ios - UIInputViewAudioFeedback 协议(protocol)的问题(未调用 enableInputClicksWhenVisible)

转载 作者:可可西里 更新时间:2023-11-01 04:35:08 26 4
gpt4 key购买 nike

我的自定义键盘和播放“咔哒”声时遇到了一些问题。我正在使用以下类和定义。

KeyboardShotInputView.h

#import <UIKit/UIKit.h>

//------------------------------------------------------------------------------
// Protocol defintion
//------------------------------------------------------------------------------

@protocol KeyboardShotInputDelegate

- (void)shotButtonDidTouchDown:(NSString*)value;
- (void)deleteButtonDidTouchDown;

@end

//------------------------------------------------------------------------------
// Interface defintition
//------------------------------------------------------------------------------

@interface KeyboardShotInputView : UIView <UIInputViewAudioFeedback>

@property (nonatomic, strong) id <KeyboardShotInputDelegate> delegate;
@property (strong, nonatomic) IBOutlet UIView *keyboard;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *shotButtonCollection;
@property (weak, nonatomic) IBOutlet UIButton *deleteButton;

- (UIView *) getKeyboardView;
- (IBAction)shotButtonPressed:(id)sender;
- (IBAction)deleteButtonPressed:(id)sender;
@end

KeyboardShotInputView.m

#import "KeyboardShotInputView.h"

@implementation KeyboardShotInputView

@synthesize keyboard;
@synthesize shotButtonCollection;
@synthesize deleteButton;

//------------------------------------------------------------------------------

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];

if (self) {
[self loadInputView];
}
return self;
}

//------------------------------------------------------------------------------

- (id)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];

if (self) {
[self loadInputView];
}
return self;
}

//------------------------------------------------------------------------------

- (void)loadInputView
{
// load nib file
UINib *inputViewNib = [UINib nibWithNibName:@"KeyboardShotInput" bundle:nil];
[inputViewNib instantiateWithOwner:self options:nil];

// layout shot input buttons
for (UIButton *btn in shotButtonCollection) {
//[btn.layer setBorderWidth:1.0];
[btn.layer setCornerRadius:5.0];
[btn.layer setShadowColor:[UIColor blackColor].CGColor];
[btn.layer setShadowOpacity:0.9];
[btn.layer setShadowRadius:1.0];
[btn.layer setShadowOffset:CGSizeMake(0.0, 1.0)];
}

// layout delete button
[self.deleteButton.layer setBorderWidth:1.0];
[self.deleteButton.layer setCornerRadius:5.0];
[self.deleteButton.layer setCornerRadius:5.0];
[self.deleteButton.layer setShadowColor:[UIColor blackColor].CGColor];
[self.deleteButton.layer setShadowOpacity:0.9];
[self.deleteButton.layer setShadowRadius:1.0];
[self.deleteButton.layer setShadowOffset:CGSizeMake(0.0, 1.0)];
}

//------------------------------------------------------------------------------

/**
* Enable input clicks.
*/
- (BOOL) enableInputClicksWhenVisible
{
NSLog(@"enableInputClicksWhenVisible: YES");
return YES;
}

//------------------------------------------------------------------------------

/**
* Return Keyboard object.
*
* @return UIView of the keyboard.
*/
- (UIView *) getKeyboardView;
{
return self.keyboard;
}

//------------------------------------------------------------------------------

/**
* Any of the shot button is pressed.
*
* @param sender Shot button object.
*/
- (IBAction)shotButtonPressed:(id)sender
{
if (!self.delegate) return;

// play click
NSLog(@"shotButtonPressed: playInputClick");
[[UIDevice currentDevice] playInputClick];

[self.delegate shotButtonDidTouchDown:[(UIButton *)sender currentTitle]];
}

//------------------------------------------------------------------------------

/**
* The delete button is pressed.
*
* @param sender DEL button object.
*/
- (IBAction)deleteButtonPressed:(id)sender
{
if (!self.delegate) return;

// play click
NSLog(@"deleteButtonPressed: playInputClick");
[[UIDevice currentDevice] playInputClick];
[self.delegate deleteButtonDidTouchDown];
}

@end

EditShootingResultTableViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];

// connect keyboard toolbar
self.keyboardToolbar = [[KeyboardToolbar alloc] init];
self.keyboardToolbar.delegate = self;

// connect shot input keyboard
self.keyboardShotInputView = [[KeyboardShotInputView alloc] init];
self.keyboardShotInputView.delegate = self;

for (UITextField* tf in self.tfShotCollection) {
tf.inputView = [self.keyboardShotInputView getKeyboardView];
}

//...
}

//------------------------------------------------------------------------------
// @name KeyboardShotInputDelegates

/**
* Receive a message every time the user touches any shot input button.
*/
- (void)shotButtonDidTouchDown:(NSString *)value
{
// handle keyboard event here...
}

//------------------------------------------------------------------------------

/**
* Receive a message every time the user touches the shot delete button.
*/
- (void)deleteButtonDidTouchDown
{
// handle keyboard event here...
}

一切正常。甚至是键盘代表的呼唤。我从方法 enableInputClicksWhenVisible 获得了除 NSLog 之外的所有 NSLog 输出。有谁知道出了什么问题?几天以来我找不到任何解决方案。 :-(

问候

最佳答案

试试这个:

AudioServicesPlaySystemSound(0x450);

关于ios - UIInputViewAudioFeedback 协议(protocol)的问题(未调用 enableInputClicksWhenVisible),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21244599/

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