Cordova应用程序无法在iPhone X(模拟器)上正确显示 [英] Cordova app not displaying correctly on iPhone X (Simulator)

查看:177
本文介绍了Cordova应用程序无法在iPhone X(模拟器)上正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我昨天在Xcode 9.0(9A235)的iPhone X模拟器上测试了我的基于Cordova的应用程序,但它看起来不太好。
首先,应用内容的上方和下方都有一个黑色区域,而不是填满整个屏幕区域。
更糟糕的是,应用内容和黑色之间是两个白条。



添加 cordova-plugin-wkwebview-engine 所以Cordova渲染使用WKWebView(不是UIWebView)修复了白条。
由于在使用 cordova-plugin-wkwebview-engine 加载从下载的图像时出现的性能和内存泄漏问题,我的应用程序未从UIWebView迁移到WKWebView Inapp将托管内容购买到HTML5画布中(由于WKWebView中的安全限制,Webview无法直接访问 file:// ,因此必须通过<$加载图像数据c $ c> cordova-plugin-file )。



这些屏幕截图显示了在<$ c $上设置蓝色背景的测试应用C><体>。
在UIWebView的上方和下方,您可以看到白色条,但不能看到WKWebView:






与填充整个屏幕区域的原生应用相比,Cordova Webviews都显示黑色区域:



解决方案

我找到白条的解决方案在下面的评论中)是使用),因此
要覆盖这两种情况,你需要用两者重载CSS规则,并依赖于



注意:



页脚按钮




  • 如果你的应用有页脚按钮(就像我的那样),你还需要申请 safe-area-inset-底部以避免它们被iPhone X上的虚拟主页按钮重叠。

  • 在我的情况下,我无法将此应用于 < body> 因为页脚是绝对定位的,所以我需要将它直接应用到页脚:


  .toolbar-footer {
margin-bottom:constant(safe-area-inset-bottom);
margin-bottom:env(safe-area-inset-bottom);
}

cordova-plugin-statusbar




  • iPhone X上的状态栏大小已更改,因此旧版本的 cordova-plugin-statusbar 在iPhone X上显示不正确

  • Mike Hartington 创建了此拉取请求应用必要的更改。

  • 这已合并到 cordova-plugin-statusbar@2.3.0 发布,所以请确保您至少使用此版本申请安全区域插页



splashscreen




  • 在iOS 11 / iPhone X上,LaunchScreen故事板约束已更改,这意味着当使用现有版本的插件时,splashscreen似乎在启动时跳转(见这里)。

  • 这是在bug中捕获的报告 CB-13505 ,修复PR cordova-ios#354 并发布于 cordova-ios@4.5.4 ,所以请确保您使用的是最新版本的 cordova-ios 平台。



设备方向




  • 在iOS 11.0上使用UIWebView时,从纵向>横向>纵向旋转会导致 safe-area-inset 不得重新应用,导致内容再次被隐藏(在下面的评论中 jms 突出显示) )。

  • 如果应用程序以横向方式启动然后旋转为纵向,也会发生这种情况

  • 通过 cordova使用WKWebView时不会发生这种情况-plugin-wkwebview-engine

  • 雷达报告: http://www.openradar.me/radar?id=5035192880201728

  • 更新:这似乎已修复在iOS 11.1中



作为参考,这是我打开的原始Cordova问题,它捕获了这个: https://issues.apache.org/jira/browse/CB-13273


I tested my Cordova-based app yesterday on the iPhone X Simulator in Xcode 9.0 (9A235) and it didn't look good. Firstly, instead of filling the full screen area, there was a black area above and below the app content. And worse, between the app content and the black was two white bars.

Adding cordova-plugin-wkwebview-engine so Cordova renders using WKWebView (not UIWebView) fixes the white bars. By my app is not migrated from UIWebView to WKWebView due to performance and memory leak issues when using cordova-plugin-wkwebview-engine which occur when loading images downloaded from Inapp Purchase hosted content into an HTML5 canvas (direct file:// access by the Webview is not possible due to security restrictions in WKWebView so the image data must be loaded via cordova-plugin-file).

These screenshots show a test app with a blue background set on the <body>. Above and below UIWebView, you can see the white bars, but not with WKWebView:

Both Cordova Webviews exhibit the black areas when compared to a native app which fills the full screen area:

解决方案

I found the solution to the white bars here:

Set viewport-fit=cover on the viewport <meta> tag, i.e.:

<meta name="viewport" content="initial-scale=1, width=device-width, height=device-height, viewport-fit=cover">

The white bars in UIWebView then disappear:

The solution to remove the black areas (provided by @dpogue in a comment below) is to use LaunchStoryboard images with cordova-plugin-splashscreen to replace the legacy launch images, used by Cordova by default. To do so, add the following to the iOS platform in config.xml:

<platform name="ios">    
    <splash src="res/screen/ios/Default@2x~iphone~anyany.png" />
    <splash src="res/screen/ios/Default@2x~iphone~comany.png" />
    <splash src="res/screen/ios/Default@2x~iphone~comcom.png" />
    <splash src="res/screen/ios/Default@3x~iphone~anyany.png" />
    <splash src="res/screen/ios/Default@3x~iphone~anycom.png" />
    <splash src="res/screen/ios/Default@3x~iphone~comany.png" />
    <splash src="res/screen/ios/Default@2x~ipad~anyany.png" />
    <splash src="res/screen/ios/Default@2x~ipad~comany.png" />   

    <!-- more iOS config... -->
</platform>

Then create the images with the following dimensions in res/screen/ios (remove any existing ones):

Default@2x~iphone~anyany.png - 1334x1334
Default@2x~iphone~comany.png - 750x1334
Default@2x~iphone~comcom.png - 1334x750
Default@3x~iphone~anyany.png - 2208x2208
Default@3x~iphone~anycom.png - 2208x1242
Default@3x~iphone~comany.png - 1242x2208
Default@2x~ipad~anyany.png - 2732x2732
Default@2x~ipad~comany.png - 1278x2732

Once the black bars are removed, there's another thing that's different about the iPhone X to address: The status bar is larger than 20px due to the "notch", which means any content at the far top of your Cordova app will be obscured by it:

Rather than hard-coding a padding in pixels, you can handle this automatically in CSS using the new safe-area-inset-* constants in iOS 11.

Note: in iOS 11.0 the function to handle these constants was called constant() but in iOS 11.2 Apple renamed it to env() (see here), therefore to cover both cases you need to overload the CSS rule with both and rely on the CSS fallback mechanism to apply the appropriate one:

body{
    padding-top: constant(safe-area-inset-top);
    padding-top: env(safe-area-inset-top);
}

The result is then as desired: the app content covers the full screen, but is not obscured by the "notch":

I've created a Cordova test project which illustrates the above steps: webview-test.zip

Notes:

Footer buttons

  • If your app has footer buttons (as mine does), you will also need to apply safe-area-inset-bottom to avoid them being overlapped by the virtual Home button on iPhone X.
  • In my case, I couldn't apply this to <body> as the footer is absolutely positioned, so I needed to apply it directly to the footer:

.toolbar-footer{
    margin-bottom: constant(safe-area-inset-bottom);
    margin-bottom: env(safe-area-inset-bottom);
}

cordova-plugin-statusbar

  • The status bar size has changed on iPhone X, so older versions of cordova-plugin-statusbar display incorrectly on iPhone X
  • Mike Hartington has created this pull request which applies the necessary changes.
  • This was merged into the cordova-plugin-statusbar@2.3.0 release, so make sure you're using at least this version to apply to safe-area-insets

splashscreen

  • The LaunchScreen storyboard constraints changed on iOS 11/iPhone X, meaning the splashscreen appeared to "jump" on launch when using existing versions of the plugin (see here).
  • This was captured in bug report CB-13505, fixed PR cordova-ios#354 and released in cordova-ios@4.5.4, so make sure you're using a recent version of the cordova-ios platform.

device orientation

  • When using UIWebView on iOS 11.0, rotating from portrait > landscape > portrait causes the safe-area-inset not to be re-applied, causing the content to be obscured by the notch again (as highlighted by jms in a comment below).
  • Also happens if app is launched in landscape then rotated to portrait
  • This doesn't happen when using WKWebView via cordova-plugin-wkwebview-engine.
  • Radar report: http://www.openradar.me/radar?id=5035192880201728
  • Update: this appears to have been fixed in iOS 11.1

For reference, this is the original Cordova issue I opened which captures this: https://issues.apache.org/jira/browse/CB-13273

这篇关于Cordova应用程序无法在iPhone X(模拟器)上正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆