如何防止离子键盘隐藏 [英] How to prevent ionic keyboard from hiding
问题描述
当我按下Ionic 1应用程序中的特定按钮时,如何防止离子键盘隐藏?
How can I prevent ionic keyboard from hiding when I press a specific button in my Ionic 1 app?
这个解决方案对我不起作用,键盘在我点击的任何地方都保持打开状态。
This solution doesn't work for me, the keyboard remains open wherever I click.
推荐答案
可以找到一个可能的解决方案这里(Sahil Dhir发送的相同链接)。我也有这个问题,这个解决方案对我有用。
A possible solution can be found here (the same link sent by Sahil Dhir). I also had this problem and this solution worked for me.
指令是:
angular.module('msgr').directive('isFocused', function($timeout) {
return {
scope: { trigger: '@isFocused' },
link: function(scope, element) {
scope.$watch('trigger', function(value) {
if(value === "true") {
$timeout(function() {
element[0].focus();
element.on('blur', function() {
element[0].focus();
});
});
}
});
}
};
});
它的用法是:
<input type="text" is-focused="true">
它基本上做的是观察输入的焦点以及输入失去焦点时(当你例如,按下键盘外面的屏幕上的按钮,它会快速将焦点分配给它。所以键盘没有时间隐藏。
What it basically does is to watch the focus of the input and whenever the input loses focus (when you press a button on the screen outside the keyboard, for example) it rapidly assigns the focus back to it. So the keyboard doesn't have time to hide.
希望它也适合你!
这篇关于如何防止离子键盘隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!