四、iOS与Web交互遇到的问题

本文讨论了iOS中Web APP开发时遇到的关键问题,包括键盘遮挡、数据交互规则、Web APP缓存清理、iOS环境下的调试方法、输入法引起的乱码问题,以及启动页和沉浸式样式配置等。
摘要由CSDN通过智能技术生成

1、Web APP 在开发过程中不可避免的涉及到输入,所以今天来解决键盘弹起遮挡的问题

1.1.从iOS原生的方面解决:
// 添加键盘监听
- (void)addNotification {

    // 键盘即将出现
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    // 键盘出现
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
    // 键盘即将消失
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    // 键盘消失
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification {
   
    [self.webView evaluateJavaScript:@"document.body.scrollTop" completionHandler:nil];
}
- (void)keyboardDidShow:(NSNotification *)notification {
    
    [self.webView evaluateJavaScript:@"document.body.scrollTop" completionHandler:nil];
}
- (void)keyboardWillHide:(NSNotification *)notification {
    
    [self.webView evaluateJavaScript:@"document.body.scrollTop = 0;" completionHandler:nil];
}
- (void)keyboardDidHide:(NSNotification *)notification {
    
    [self.webView evaluateJavaScript:@"document.body.scrollTop" completionHandler:nil];
}
1.2.从Web方面解决(在main.js中):
mounted() {
	let myFunction
	if (isiOS) {
		document.body.addEventListener('focusin', () => { // 软键盘弹起事件
			clearTimeout(myFunction)
		})
     	document.body.addEventListener('focusout', () => { // 软键盘关闭事件
        	clearTimeout(myFunction)
        	myFunction = setTimeout(function() {
          		window.scrollTo({top: 0, left: 0, behavior: 'smooth'}) // 当键盘收起的时候让页面回到原始位置
        	}, 10)
      })
    }
  }
  
备注:由于很多Web APP引入了FastClick组件,在iOS设备上input标签键盘弹起会不灵敏,需要在main.js
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值