ionic1 和普通cordova的大家都知道 就是看ionic3 和4
https://blog.csdn.net/sean_css/article/details/70243893
ionic cordova plugin add ionic-plugin-keyboard
$ npm install --save @ionic-native/keyboard
經過本人測試 這個方法 ionic1 ionic3 都可以用
ionic3 把方法寫到 構造器 或者 生命周期事件里面就行
ionic1里面的用法 addEventListener 這種這種寫法在ionic3 的ts 中無法與外部變量通信 應該是機制問題
//監聽軟鍵盤彈出 window.addEventListener('native.keyboardshow', function (e:any) { //e.keyboardHeight 表示軟件盤顯示的時候的高度 //alert(JSON.stringify(e)) this.keyboardshowHeightBottom=e.keyboardHeight+'px'; }); //監聽軟鍵盤關閉 window.addEventListener('native.keyboardhide', function (e) { //e.keyboardHeight 表示軟件盤顯示的時候的高度 //alert(JSON.stringify(e)) this.keyboardshowHeightBottom='0px'; });
ionic3 里面的用法
//rxjs import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/fromEvent'; Observable.fromEvent(window, "native.keyboardshow") .debounceTime(100) .subscribe((event: any) => { alert('顯示:'+JSON.stringify(event)) //this.keyboardshowHeightBottom=event.keyboardHeight+'px'; }); Observable.fromEvent(window, "native.keyboardhide") .debounceTime(100) .subscribe((event: any) => { //alert('關閉'+JSON.stringify(event)) });