cordova 导致css中绝对定位top:0会被顶到视图之外

本文解决iOS中WebView全屏显示时状态栏遮挡、键盘弹出时页面不收缩及自动聚焦失效等问题,通过修改MainViewController.m、配置cordova插件及添加JS调用实现。
  • IOS7+ webview全屏导致状态栏悬浮在页面上
    解决方案:打开 ios项目/classes/MainViewController.m,修改viewWillAppear方法
- (void)viewWillAppear:(BOOL)animated  
{  
    // View defaults to full size.  If you want to customize the view's size, or its subviews (e.g. webView),  
    // you can do so here.  
    if([[[UIDevice currentDevice]systemVersion ] floatValue]>=7)  
    {  
        CGRect viewBounds=[self.webView  bounds];  
        viewBounds.origin.y=20;  
        viewBounds.size.height=viewBounds.size.height-20;  
        self.webView.frame=viewBounds;  
    }  
  
    [super viewWillAppear:animated];  
} 

PS:更新cordova-plugin-statusbar插件为2.2.3之后,好像失效了
暂时把配置项改成这样

  <preference name="StatusBarStyle" value="defaults" />
  • ios聚焦打开键盘时,webview没有收缩高度,导致css中绝对定位top:0会被顶到视图之外
    解决方案:添加cordova-plugin-keyboard插件,然后js调用插件的方法,使开启键盘时收缩webview
// 安装cordova-plugin-keyboard
cordova plugin add cordova-plugin-keyboard

然后在deviceready事件中调用全局Keyboard.shrinkView方法

document.addEventListener('deviceready', () => {
  window.Keyboard.shrinkView(true);
  // 其他代码
  ...............
}
  • ios自动聚焦无效(例如 autofocus、jq的$(xxx).focus())
    解决方案:在cordova配置文件config.xml中增加以下配置:
<preference name="KeyboardDisplayRequiresUserAction" value="false" />

持续更新,暂时 只碰到 || 只想起 这几个



作者:kamifun
链接:https://www.jianshu.com/p/bf4b0a5d459a
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

转载于:https://www.cnblogs.com/zzsdream/p/10041953.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值