Ответ 1
Мы можем показывать виртуальную клавиатуру устройства, даже если подключена клавиатура Bluetooth. Для этого нам нужно использовать inputAccessoryView
.
Нам нужно добавить код ниже в приложении delegate.h
@property (strong, nonatomic) UIView *inputAccessoryView;
добавить ниже уведомления в метод (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
в delegate.m
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldBegan:) name:UITextFieldTextDidBeginEditingNotification object:nil];
Это вызовет метод ниже, когда мы сосредоточимся на textField
.
//This function responds to all `textFieldBegan` editing
// we need to add an accessory view and use that to force the keyboards frame
// this way the keyboard appears when the bluetooth keyboard is attached.
-(void) textFieldBegan: (NSNotification *) theNotification
{
UITextField *theTextField = [theNotification object];
if (!inputAccessoryView) {
inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[inputAccessoryView setBackgroundColor:[UIColor lightGrayColor]];
}
theTextField.inputAccessoryView = inputAccessoryView;
[self performSelector:@selector(forceKeyboard) withObject:nil afterDelay:0];
}
и код для "forceKeyboard" равен
-(void) forceKeyboard
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
inputAccessoryView.superview.frame = CGRectMake(0, 420, screenHeight, 352);
}
Это отлично работает для нас. Мы используем скрытое текстовое поле для ввода ввода с клавиатуры bluetooth, а для всех других текстовых полей мы используем виртуальную клавиатуру устройства, которая отображается с помощью inputAccessoryView
.
Пожалуйста, дайте мне знать, если это поможет, и если вам нужна более подробная информация.