我遇到了需要在 iOS 上以编程方式关闭键盘的情况。为了解决它,我正在使用这段代码:
Keyboard.close();
它会关闭键盘,但只要我触摸屏幕,它就会重新打开。有其他人遇到过这种情况吗?谢谢!
最佳答案
我在 ios 11 中在模态框内使用 iframe 时也遇到了这个问题。如果我使用 this.keyboard.close() 手动关闭键盘,它会在每次触摸时重新打开。我终于解决了
https://forum.ionicframework.com/t/keyboard-reopens-after-close-repeatedly-on-ios/107347/2
在嵌入 iframe 的页面中添加以下内容
嵌入.ts
declare var cordova;
@ViewChild('ioshack') ioshack;
ionViewWillLeave() {
if(cordova.plugins.Keyboard.isVisible){
this.ioshack.setFocus();
}
}
嵌入.html
<ion-content>
<iframe [src]="url" width="100%" height="100%" frameborder="0" allowfullscreen>
</iframe>
<ion-input #ioshack type="text" value="" class="ioshack" style="height: 0px;"> </ion-input>
</ion-content>
关于ios - Ionic 2 键盘关闭后重新打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45420315/