javascript 防止iOS键盘在cordova 3.5中滚动页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24865973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Preventing iOS Keyboard from scrolling page in cordova 3.5
提问by user3558515
I am using Cordova 3.5 and jQuery mobile to build an iOS app. I have disabled scrolling in most of the app; however, when I select an input field, the iOS keyboard opens and scrolls the page up. I do not want this functionality. Since the input is high enough that the keyboard would not cover it up, I want the page to remain still while the keyboard covers up the bottom part of the page.
我正在使用 Cordova 3.5 和 jQuery mobile 来构建一个 iOS 应用程序。我在大多数应用程序中禁用了滚动;但是,当我选择一个输入字段时,iOS 键盘会打开并向上滚动页面。我不想要这个功能。由于输入足够高,键盘不会覆盖它,我希望页面保持静止,而键盘覆盖页面的底部。
This question is similar to a number of others like this one, and is the opposite of the problem posted here.
However, none of the posted answers worked for me, so I will post my solution here.
但是,没有一个已发布的答案对我有用,因此我将在此处发布我的解决方案。
回答by user3558515
Add this pluginwith
添加这个插件与
cordova plugin add https://github.com/driftyco/ionic-plugins-keyboard.git
in the command line.
在命令行中。
Add the following line anywhere it the javascript to disable scrolling from the keyboard.
在 javascript 的任何位置添加以下行以禁用从键盘滚动。
cordova.plugins.Keyboard.disableScroll(true);
In my use case, I added a deviceready
event listener to evaluate this line, disabling the automatic keyboard scrolling everywhere in the app.
在我的用例中,我添加了一个deviceready
事件侦听器来评估这一行,禁用应用程序中随处可见的自动键盘滚动。
That's it!
而已!
回答by tfmontague
From my experience, and saying this as a developer who avoids 3rd party plugins as much as possible, I've found that virtual keyboard issues in Cordova are best solved with a plugin.
根据我的经验,作为一个尽可能避免使用 3rd 方插件的开发人员,我发现 Cordova 中的虚拟键盘问题最好使用插件来解决。
The Cordova plugin directory has several keyboard
plugins
(http://cordova.apache.org/plugins/?q=keyboard)
Cordova 插件目录有几个keyboard
插件(http://cordova.apache.org/plugins/?q=keyboard)
I recommend the following plugin:
https://github.com/cjpearson/cordova-plugin-keyboard
我推荐以下插件:https:
//github.com/cjpearson/cordova-plugin-keyboard
Which provides the following command to disable scrolling when the virtual keyboard is open.
它提供了以下命令来在虚拟键盘打开时禁用滚动。
cordova.plugins.Keyboard.disableScrollingInShrinkView(true);