iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了显示iPhone软键盘,即使连接了硬件键盘大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的iPad应用程序使用作为硬件键盘的外部“设备”。但是,在设置的某个时刻,我需要输入文本,我不能使用“设备”(“设备”不是键盘)。
那么,有没有办法强制弹出软键盘,甚至认为我有一个硬件键盘连接?

解决方法

是。我们已经在我们的几个应用程序中完成了这一点,当用户将蓝牙扫描仪“键盘”与设备配对时。你可以做的是确保你的textField有一个inputAccessoryView,然后强制inputAccessoryView的框架。这将导致键盘在屏幕上显示

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

//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,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);
}

然后在我们的applicationDidFinishLaunching中,我们添加了这个通知观察者,所以我们可以随时收到一个文本字段开始编辑的事件

//Setup the textFieldNotifications
    [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(textFieldBegan:) name:UITextFieldTextDidBeginEdiTingNotification object:nil];

希望有帮助!

大佬总结

以上是大佬教程为你收集整理的显示iPhone软键盘,即使连接了硬件键盘全部内容,希望文章能够帮你解决显示iPhone软键盘,即使连接了硬件键盘所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。