//ios手机 监听键盘弹出、隐藏事件
// 键盘弹出事件处理
window.addEventListener('focusin',this.showMarginBottom());
//键盘收起事件处理
window.addEventListener('focusout',this.hideMarginBottom());
//安卓手机
let innerHeight = window.innerHeight;
window.addEventListener('resize', () => {
let newInnerHeight = window.innerHeight;
if (innerHeight > newInnerHeight) {
// 键盘弹出事件处理
this.showMarginBottom();
} else {
// 键盘收起事件处理
this.hideMarginBottom();
}
})
//具体业务代码
showMarginBottom(){
console.log("键盘弹出事件处理");
this.$refs.area_ctrl.style.marginBottom="-50%";
},
hideMarginBottom(){
console.log("键盘收起事件处理");
this.$refs.area_ctrl.style.marginBottom="0";
},
//要记得 移除监听
window.removeEventListener('resize', () => {
let newInnerHeight = window.innerHeight;
if (innerHeight > newInnerHeight) {
// 键盘弹出事件处理
this.showMarginBottom();
} else {
// 键盘收起事件处理
this.hideMarginBottom();
}
})
//ios手机 移除键盘弹出、隐藏事件
// 键盘弹出事件处理
window.removeEventListener('focusin',this.showMarginBottom);
//键盘收起事件处理
window.removeEventListener('focusout',this.hideMarginBottom);
···
2023-11-15【技术】关于监听手机键盘弹出/隐藏事件
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 开发需求:对键盘弹出及隐藏事件进行监听 需要通过NotificationCenter对键盘事件进行监听 如果要监听...
- 相信看到这个标题,大家都会潜意识觉得:Activity中没有可以复写的方法么?或者说,没有什么listener可以...
- // NotificationCenter.default.addObserver(self, sele...