- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经进行了很长时间的搜索,到目前为止,我还没有找到能够以编程方式显示软键盘的 PhoneGap/Cordova 应用程序的有效解决方案。
场景:
我们有一个 PhoneGap 应用程序 - 一个在 jQuery Mobile 中创建的网站 - 在某一时刻向用户显示一个对话框。该对话框也是一个网页,并且有一个输入文本框,用户应在其中输入代码。
问题:
显示代码对话框时,使用 JavaScript 聚焦输入框。但是,由于 iPhone 内部浏览器的限制,只有当用户真正在输入文本框内单击时,软键盘才会出现。
我们尝试过的:
有什么想法吗?
<小时/>编辑:这个问题中提到的限制仅适用于内置浏览器...如果您的目标是 Opera,那么您使用以下代码即可成功:
var e = jQuery.Event("keydown", { keyCode: 37 });
$('#element').focus().trigger(e);
<小时/>
编辑2:这是可在插件中使用的最终工作PhoneGap代码:
keyboardhelper.h
//
// keyboardHelper.h
// soft keyboard displaying plugin for PhoneGap
//
// Copyright 2012 Martin Ambrus.
//
#import <Foundation/Foundation.h>
#ifdef CORDOVA_FRAMEWORK
#import <Cordova/CDVPlugin.h>
#else
#import "CDVPlugin.h"
#endif
@interface keyboardHelper : CDVPlugin {
NSString *callbackID;
}
@property (nonatomic, copy) NSString *callbackID;
- (void)showKeyboard:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
@end
keyboardhelper.m
//
// keyboardHelper.m
// soft keyboard displaying plugin for PhoneGap
//
// Copyright 2012 Martin Ambrus.
//
#import "keyboardHelper.h"
#import "AppDelegate.h"
@implementation keyboardHelper
@synthesize callbackID;
-(void)showKeyboard:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
self.callbackID = [arguments pop];
//Get text field coordinate from webview. - You should do this after the webview gets loaded
//myCustomDiv is a div in the html that contains the textField.
int textFieldContainerHeightOutput = [[((AppDelegate *)[[UIApplication sharedApplication] delegate]).viewController.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"myCustomDiv\").offsetHeight;"] intValue];
int textFieldContainerWidthOutput = [[((AppDelegate *)[[UIApplication sharedApplication] delegate]).viewController.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"myCustomDiv\").offsetWidth;"] intValue];
int textFieldContainerYOffset = [[((AppDelegate *)[[UIApplication sharedApplication] delegate]).viewController.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"myCustomDiv\").offsetTop;"] intValue];
int textFieldContainerXOffset = [[((AppDelegate *)[[UIApplication sharedApplication] delegate]).viewController.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"myCustomDiv\").offsetLeft;"] intValue];
UITextField *myTextField = [[UITextField alloc] initWithFrame: CGRectMake(textFieldContainerXOffset, textFieldContainerYOffset, textFieldContainerWidthOutput, textFieldContainerHeightOutput)];
[((AppDelegate *)[[UIApplication sharedApplication] delegate]).viewController.webView addSubview:myTextField];
myTextField.delegate = self;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @"ok"];
[self writeJavascript:[pluginResult toSuccessCallbackString:self.callbackID]];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
//here you create your request to the server
return NO;
}
-(BOOL)textFieldDidEndEditing:(UITextField *)textField
{
//here you create your request to the server
return NO;
}
@end
javascript
var keyboardHelper = {
showKeyboard: function(types, success, fail) {
return Cordova.exec(success, fail, "keyboardHelper", "showKeyboard", types);
}
};
最佳答案
现在您可以通过 config.xml
条目解决问题,添加:
<preference name="keyboardDisplayRequiresUserAction" value="false" />
关于iphone - 在 PhoneGap 应用程序中以编程方式在 iPhone 上显示软键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12140484/
我正试图找到一个基准来衡量用户愿意等待远程服务响应的时间。在我的例子中,响应是非常有用的,但不是对数据输入的业务关键验证。我想 HCI 领域一定已经在这方面做了一些工作。 如果您知道软实时响应的普遍接
这个问题在这里已经有了答案: What's the difference between SoftReference and WeakReference in Java? (12 个回答) 关闭6年前
社区维基 我不在乎声誉点,我只想要好的答案。请随意将此问题标记为社区 wiki。 上下文 我一直在研究《理性策划者》,并发现了以下观察结果: 逻辑编程非常有趣。 逻辑编程有时是违反直觉的 逻辑编程通常
我已阅读this article关于Java中不同类型的引用(强引用、软引用、弱引用、幻像引用),但我不太理解。 这些引用类型之间有什么区别?每种类型何时使用? 最佳答案 Java 提供了两种不同类型
我需要一个带有弱键或软键的并发 HashMap ,其中等式是 equals 而不是 ==。 对于此类键,Google Collection 默认选择 ==。 有没有办法覆盖这个选择?我应该如何进行?
我读了here使用下面的命令我们可以在 Linux 系统上模拟硬重启: echo 1 > /proc/sys/kernel/sysrq echo b > /proc/sysrq-trigger 但我想
我正在使用软件 I²C实现读取一组 Sensirion SHT21 传感器。我正在尝试找出一种让传感器回答以查看它们是否实际连接到设备的方法。我正在使用 Arduino,这意味着我所有的代码都是 C/
这个问题在这里已经有了答案: How do you determine using stat() whether a file is a symbolic link? (1 个回答) 关闭 9 年前
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我一直在使用 ICS 上的 Wifi Direct API,但有点卡住了。 在 API 中,有一个名为 createGroup 的方法可以在手机上创建一个基于遗留软件的接入点。这很棒并且有效,但我似乎
当我在 ruby 中有一个数组时,我可以在其上运行 delete_if block 。问题是它从我的数组中删除了元素。我想要相同的功能,只是不对原始数组进行更改,而是返回一个删除了对象的新数组。
在 Ubuntu Virtualbox 上运行从 Windows 移植的音频应用程序时,它报告以下内容: Devices found: OpenAL Soft OpenAL Soft 40964 in
下面是我的数据库结构的简化版本(在 MVC 2 中构建一个概念验证站点,使用 Entity Framework 4 作为我的 ORM): [Stores] StoreID (PK) StoreName
我用 ESP8266 创建了一个软 AP,我通过 android 6.0 marshmallow mobile 连接到它。连接后,如果我忽略它并打开浏览器窗口打开我的网络服务器页面或使用自定义构建的应
如何应用 Three.js online editor 中所示的 PCF (SOFT) 阴影类型以 JavaScript 代码的形式发送到你的渲染器? 最佳答案 要使用该类型的阴影,您需要使用相应类型
我知道 Wifi Direct 的工作原理是在其中一台设备中创建软 AP(软件接入点)。我也知道很多 Android 支持 Wifi Direct,但 iPhone 不支持。 我的问题是:是否可以创建
我有一个在 14.04.05 LTS 上运行的 Ubuntu 服务器。 此服务器上还安装了几个 ugins mongodb 应用程序。 MongoDB版本为3.4.2 我正在尝试增加 mongodb
我是一名优秀的程序员,十分优秀!