iOS/iPhone: 网页应用启动画面未显示

22

我在我的网页应用程序的<head>中有以下代码,但在DOM加载时,我的iPhone 3GS只显示白屏而不是启动画面。

<meta name="viewport" content="width=device-width, initial-scale=1"> 
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />

<!--STYLES-->

<!--SCRIPTS-->

<!-- iPhone LAUNCHSCREEN-->
<link href="includes/images/apple-launch-480h.png" sizes="320x480" media="(device-height: 480px)" rel="apple-touch-startup-image">
<!-- iPhone (Retina) LAUNCHSCREEN-->
<link href="includes/images/apple-launch-480h2X.png" sizes="640x920" media="(device-height: 480px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">
<!-- iPhone 5+ LAUNCHSCREEN-->
<link href="includes/images/apple-launch-568h.png" sizes="640x1136" media="(device-height: 568px)" rel="apple-touch-startup-image">

如何在所有版本的 iPhone 上正确显示启动画面? 我没有展示代码,但我的 Web 应用程序图标可以在主页上使用。我正在使用 jQuery Mobile 构建此 Web 应用程序。

我已确认 PNG 图像的大小是完全正确的,并且已多次删除 Web 应用程序图标、刷新并重新添加到主屏幕上,但都无效。在 StackOverflow 上找到的解决方案都没有起作用。我还没有尝试 JavaScript 解决方案,因为我相信一定有纯 CSS 的解决方案。

2个回答

52

sizes 属性适用于 apple-touch-icon,但不适用于 apple-touch-startup-image。唯一的方法是使用媒体查询来定位启动图像。Adam 的回答很好,但它依赖于 <link> 的特定顺序,因为媒体查询未指定。以下是完全限定的媒体查询:

<!-- iPhone -->
<link href="apple-touch-startup-image-320x460.png"
      media="(device-width: 320px) and (device-height: 480px)
         and (-webkit-device-pixel-ratio: 1)"
      rel="apple-touch-startup-image">
<!-- iPhone (Retina) -->
<link href="apple-touch-startup-image-640x920.png"
      media="(device-width: 320px) and (device-height: 480px)
         and (-webkit-device-pixel-ratio: 2)"
      rel="apple-touch-startup-image">
<!-- iPhone 5 -->
<link href="apple-touch-startup-image-640x1096.png"
      media="(device-width: 320px) and (device-height: 568px)
         and (-webkit-device-pixel-ratio: 2)"
      rel="apple-touch-startup-image">
<!-- iPad (portrait) -->
<link href="apple-touch-startup-image-768x1004.png"
      media="(device-width: 768px) and (device-height: 1024px)
         and (orientation: portrait)
         and (-webkit-device-pixel-ratio: 1)"
      rel="apple-touch-startup-image">
<!-- iPad (landscape) -->
<link href="apple-touch-startup-image-748x1024.png"
      media="(device-width: 768px) and (device-height: 1024px)
         and (orientation: landscape)
         and (-webkit-device-pixel-ratio: 1)"
      rel="apple-touch-startup-image">
<!-- iPad (Retina, portrait) -->
<link href="apple-touch-startup-image-1536x2008.png"
      media="(device-width: 768px) and (device-height: 1024px)
         and (orientation: portrait)
         and (-webkit-device-pixel-ratio: 2)"
      rel="apple-touch-startup-image">
<!-- iPad (Retina, landscape) -->
<link href="apple-touch-startup-image-1496x2048.png"
      media="(device-width: 768px) and (device-height: 1024px)
         and (orientation: landscape)
         and (-webkit-device-pixel-ratio: 2)"
      rel="apple-touch-startup-image">

请注意,某些视口会导致您的 Web 应用在 iPhone 5 上出现边框:

<!-- Letterboxed on iPhone 5 -->
<meta name="viewport"
      content="width=device-width">
<meta name="viewport"
      content="width=320">
<!-- Not letterboxed on iPhone 5 -->
<meta name="viewport"
      content="initial-scale=1.0">
<meta name="viewport"
      content="width=320.1">

我维护一个包含启动图片和图标的最小iOS Web应用程序的Gist。如果您想了解更多评论,我还写了一篇关于iPhone 5启动画面的博客文章。


太棒了!我会试一下的。谢谢! - Mark Rummel
3
如果有帮助的话,iPhone 6 的启动画面尺寸在这里:https://dev59.com/1IPba4cB1Zd3GeqPv7NC#26057714。 - Dunc
@TaylorFausak,你能否制作并提供一个包含启动屏幕图像的模板GIT项目?我认为目前没有可用的模板,并且我从未成功地在主屏幕Web应用程序上看到过任何闪屏。 - Flavien Volken
我不想为此维护一个Git存储库。除了图像本身之外,您需要的所有内容都在Gist中提供。(您甚至可以像普通的Git存储库一样克隆Gist!) - Taylor Fausak

3
以下是需要使用的尺寸:

<!-- iPhone -->
<link href="http://www.example.com/mobile/images/apple-startup-iPhone.jpg" media="(device-width: 320px)" rel="apple-touch-startup-image">

<!-- iPhone (Retina) -->
<link href="http://www.example.com/mobile/images/apple-startup-iPhone-RETINA.jpg" media="(device-width: 320px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">

<!-- iPhone Tall (Retina) -->
<link href="http://www.example.com/mobile/images/apple-startup-iPhone-Tall-RETINA.jpg" rel="apple-touch-startup-image" sizes="640x1096">

<!-- iPad (portrait) -->
<link href="http://www.example.com/mobile/images/apple-startup-iPad-Portrait.jpg" media="(device-width: 768px) and (orientation: portrait)" rel="apple-touch-startup-image">

<!-- iPad (landscape) -->
<link href="http://www.example.com/mobile/images/apple-startup-iPad-Landscape.jpg" media="(device-width: 768px) and (orientation: landscape)" rel="apple-touch-startup-image">

<!-- iPad (Retina, portrait) -->
<link href="http://www.example.com/mobile/images/apple-startup-iPad-RETINA-Portrait.jpg" media="(device-width: 768px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">

<!-- iPad (Retina, landscape) -->
<link href="http://www.example.com/mobile/images/apple-startup-iPad-RETINA-Landscape.jpg" media="(device-width: 768px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">

1
你在 iPhone Tall 上使用了 640 x 1096,但是在 苹果的 iOS 人机界面指南 中他们说应该是 640 x 1136。哪一个是正确的? - Mark Rummel
4
你没有考虑状态栏占用的40像素。640 x 1136是用于应用启动图像的尺寸。正确的尺寸是640 x 1096 - adamdehaven

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接