javascript 键盘显示时离子内容不向下滚动(Android)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27837270/
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
Ionic ion-content not scrolling down when keyboard shows (Android)
提问by jvannistelrooy
I have a simple view with a login form. On Android, if the keyboard is opened, the content is not scrolling up to prevent it from getting behind the keyboard.
我有一个带有登录表单的简单视图。在 Android 上,如果键盘已打开,内容不会向上滚动以防止其位于键盘后面。
I followed the Keyboard instructions from the docs, and read a lot of forum posts, but I haven't figured it out.
我按照文档中的键盘说明进行操作,并阅读了很多论坛帖子,但我还没有弄清楚。
I installed the Keyboard plugin com.ionic.keyboard
.
我安装了键盘插件com.ionic.keyboard
。
This is the structure of the page:
这是页面的结构:
<ion-nav-view>
<ion-view>
<ion-content>
...<form>..Login form..</form>...
</ion-content>
</ion-view>
</ion-nav-view>
If I put some extra dummy content in the page, it shows that ion-content is indeed scrollable. However, it's not moving up when the keyboard is opened by focusing on an input.
如果我在页面中添加了一些额外的虚拟内容,则表明 ion-content 确实是可滚动的。但是,当通过专注于输入而打开键盘时,它不会向上移动。
- Ionic version?
1.0.0-beta.13
- Is my app fullscreen? No
- Did I test if the keyboard plugin is working? Yes
- 离子版?
1.0.0-beta.13
- 我的应用程序是全屏的吗?不
- 我是否测试过键盘插件是否正常工作?是的
Is there anything else I have to do?
还有什么我需要做的吗?
回答by Nizar B.
In the section where you declare the keyboard plugin, try to add this:
在声明键盘插件的部分,尝试添加以下内容:
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(false);
}
回答by Mithlesh Kumar
I have prevent this scrolling property in my project by setting below values in AndroidManifest.xmlfile.
我通过在AndroidManifest.xml文件中设置以下值来防止我的项目中出现此滚动属性。
android:windowSoftInputMode = "adjustNothing"
android:windowSoftInputMode = "adjustNothing"
Please check whether android:windowSoftInputMode
value is adjustResize
or not in AndroidManifest.xml. If not please update it to adjustResize
.
请检查android:windowSoftInputMode
值是否adjustResize
在AndroidManifest.xml 中。如果不是,请将其更新为adjustResize
.
I hope this will you. Thanks
我希望这会是你。谢谢
回答by 1nstinct
On both Android and iOS, Ionic will attempt to prevent the keyboard from obscuring inputs and focusable elements when it appears by scrolling them into view. In order for this to work, any focusable elements must be within a Scroll View or a directive such as Content that has a Scroll View.
在 Android 和 iOS 上,Ionic 将尝试通过将键盘滚动到视图中来防止键盘在输入和可聚焦元素出现时遮住它们。为了使其工作,任何可聚焦元素都必须在滚动视图或具有滚动视图的指令(例如内容)中。
回答by yishaiz
In my case there is a footer that hides the input when the keyboard is showing.
在我的情况下,有一个页脚可以在显示键盘时隐藏输入。
Seeing github.com/driftyco/ionic/issues/2151, although its a closed bug it seems that its still an issue.
看到github.com/driftyco/ionic/issues/2151,虽然它是一个封闭的错误,但它似乎仍然是一个问题。
To me it seems that the scrolling doesn't know how to calculate properly whether it should scroll or not, because it doesn't take under account the footer in its calculations. If the content is big enough from the first place then it knows it has to scroll anyway.
对我来说,滚动似乎不知道如何正确计算是否应该滚动,因为它在计算中没有考虑页脚。如果内容从一开始就足够大,那么它知道无论如何都必须滚动。
I've ended up using
我最终使用了
$timeout(function() {
$ionicScrollDelegate.scrollBottom(true);
}, 300);
and adding some <br/>
at the bottom of my ion-content
.
There is enough space so it won't effect anything for me, bug will cause the scroll to work properly.
并<br/>
在我的ion-content
. 有足够的空间所以它不会对我产生任何影响,错误会导致滚动正常工作。