即使连接了硬件键盘,仍显示iPhone软键盘 [英] Show iPhone soft keyboard even though a hardware keyboard is connected

查看:167
本文介绍了即使连接了硬件键盘,仍显示iPhone软键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iPad应用程式使用外部「装置」作为硬体键盘。但是,在设置的某一点,我需要输入文本,我不能使用设备(设备不是一个键盘)。
所以,有没有办法强迫弹出软键盘,即使我有一个硬件键盘连接?

解决方案

是。我们在我们的一些应用中完成了这项工作,当用户拥有与设备配对的蓝牙扫描仪键盘时。你可以做的是确保你的textField有一个inputAccessoryView,然后自己强制inputAccessoryView的框架。这将导致键盘显示在屏幕上。



我们在AppDelegate中添加了以下两个函数。 'inputAccessoryView'变量是一个UIView *我们在我们的应用程序委托中声明:

  //此函数响应所有textFieldBegan编辑
//我们需要添加一个附件视图,并使用它来强制键盘框架
//这种方式键盘出现时,扫描仪附加
- (void)textFieldBegan:(NSNotification * )theNotification
{
UITextField * theTextField = [theNotification object];
// NSLog(@textFieldBegan:%@,theTextField);

if(!inputAccessoryView){
inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0,0,navigationController.view.frame.size.width,1)
}

theTextField.inputAccessoryView = inputAccessoryView;

[self performSelector:@selector(forceKeyboard)withObject:nil afterDelay:0];
}

//更改inputAccessoryView框架 - 这对于纵向是正确的,对于横向使用不同的
//框架
- (void)forceKeyboard
{
inputAccessoryView.superview.frame = CGRectMake(0,759,768,265);然后在我们的applicationDidFinishLaunching中,我们添加了这个通知观察器,所以我们可以随时得到一个事件。文本字段开始编辑

  //设置textFieldNotifications 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (textFieldBegan :) name:UITextFieldTextDidBeginEditingNotification object:nil];

希望有所帮助!


My iPad app uses an external "device" that acts as a hardware keyboard. But, at some point in the settings, I need to input text and I can't use the "device" ("device" is not a keyboard). So, is there any way to force pop the soft keyboard even thought I have a hardware keyboard connected?

解决方案

Yes. We've done this in a few of our apps for when the user has a Bluetooth scanner "keyboard" paired with the device. What you can do is make sure your textField has an inputAccessoryView and then force the frame of the inputAccessoryView yourself. This will cause the keyboard to display on screen.

We added the following two functions to our AppDelegate. The 'inputAccessoryView' variable is a UIView* we have declared in our app delegate:

//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 scanner is attached
-(void) textFieldBegan: (NSNotification *) theNotification
{
    UITextField *theTextField = [theNotification object];
    //  NSLog(@"textFieldBegan: %@", theTextField);

    if (!inputAccessoryView) {
        inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, navigationController.view.frame.size.width, 1)];
    }

    theTextField.inputAccessoryView = inputAccessoryView;

    [self performSelector:@selector(forceKeyboard) withObject:nil afterDelay:0];
}

//Change the inputAccessoryView frame - this is correct for portrait, use a different
// frame for landscape
-(void) forceKeyboard
{
    inputAccessoryView.superview.frame = CGRectMake(0, 759, 768, 265);
}

Then in our applicationDidFinishLaunching we added this notification observer so we would get an event anytime a text field began editing

    //Setup the textFieldNotifications
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldBegan:) name:UITextFieldTextDidBeginEditingNotification object:nil];

Hope that helps!

这篇关于即使连接了硬件键盘,仍显示iPhone软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆