iOS网页应用程序(特别是iPad)的多个“apple-touch-startup-image”分辨率?

64

我写了一个基于HTML5的iOS网页应用,所有功能似乎都正常运行,但我正在尝试通过多个启动屏幕来优化它。iPhone/iPod touch使用320x460的PNG图片效果良好,如下所示:

<link rel="apple-touch-startup-image" href="img/startup_screen-320x460.png" />

我找到了很多文档,说iPad的启动图像应该像iPhone/iPod Touch一样,在高度上减去20个像素以适应状态栏,从而得到768x1004(竖屏)或1024x748(横屏)的分辨率。但是在我的测试中(目前使用运行iOS 3.2.2的iPad),只有768x1004(竖屏)的分辨率有效(但在横屏模式下不正确——狭窄了20个像素)。

我尝试了以下操作(根据apple-touch-icon链接的功能猜测),但没有成功:

<link rel="apple-touch-startup-image" href="img/startup_screen-320x460.png" />
<link rel="apple-touch-startup-image" sizes="1024x748" href="img/startup_screen-1024x748.png" />
<link rel="apple-touch-startup-image" sizes="768x1004" href="img/startup_screen-768x1004.png" />

如果最后一个link元素是1024x748分辨率的图像,将会渲染灰色背景(但从不是768x1004分辨率)。因此,显然apple-touch-startup-image link不支持sizes属性。

这在iOS的新版本中是否支持?有没有办法支持多个启动图像?我应该创建一个1024x768的启动图像吗?如果是这样,它会被缩小适配iPhone/iPod touch吗?或者,我应该放弃为iPad设置启动图像?


Morgant - 感谢你的好问题!只是出于好奇...你知道是否有可能为iPhone 4指定高分辨率启动屏幕(即640x920)吗? - mattstuehler
我的回答解决了你的问题吗?如果是的话,你可以选择它作为答案吗?谢谢。 - derickito
根据苹果公司的官方文档(https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html#//apple_ref/doc/uid/TP40002051-CH3-SW1),你所说的第一张图片尺寸应该是320 x 480,而不是320 x 460。 - alejnavab
@alej27 感谢您指出这一点,我相信在我最初提出问题的5年里,大小已经发生了变化(那个时期的许多答案包括相同的初始值)。 - morgant
14个回答

80

针对 iPad 和 iPhone(横屏 || 竖屏)以及(Retina || 非 Retina)的 启动图像触摸图标 的决定性解决方案:

        <!-- iPhone ICON -->
        <link href="apple-touch-icon-57x57.png" sizes="57x57" rel="apple-touch-icon">
        <!-- iPad ICON-->
        <link href="apple-touch-icon-72x72.png" sizes="72x72" rel="apple-touch-icon">
        <!-- iPhone (Retina) ICON-->
        <link href="apple-touch-icon-114x114.png" sizes="114x114" rel="apple-touch-icon">
        <!-- iPad (Retina) ICON-->
        <link href="apple-touch-icon-144x144.png" sizes="144x144" rel="apple-touch-icon">

        <!-- iPhone SPLASHSCREEN-->
        <link href="apple-touch-startup-image-320x460.png" media="(device-width: 320px)" rel="apple-touch-startup-image">
        <!-- iPhone (Retina) SPLASHSCREEN-->
        <link href="apple-touch-startup-image-640x920.png" media="(device-width: 320px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">
        <!-- iPad (portrait) SPLASHSCREEN-->
        <link href="apple-touch-startup-image-768x1004.png" media="(device-width: 768px) and (orientation: portrait)" rel="apple-touch-startup-image">
        <!-- iPad (landscape) SPLASHSCREEN-->
        <link href="apple-touch-startup-image-748x1024.png" media="(device-width: 768px) and (orientation: landscape)" rel="apple-touch-startup-image">
        <!-- iPad (Retina, portrait) SPLASHSCREEN-->
        <link href="apple-touch-startup-image-1536x2008.png" media="(device-width: 1536px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">
        <!-- iPad (Retina, landscape) SPLASHSCREEN-->
        <link href="apple-touch-startup-image-2048x1496.png" media="(device-width: 1536px)  and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">
        <!-- iPhone 6/7/8 -->
        <link href="/images/favicon/750x1334.png" media="(device-width: 375px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
        <!-- iPhone 6 Plus/7 Plus/8 Plus -->
        <link href="/images/favicon/1242x2208.png" media="(device-width: 414px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image" />

1
第三个“link”标记中是否需要“packaging/”? - Mahdi Ghiasi
6
对于那些来到这里想要知道 iPhone 5 启动图片尺寸的人:请查看此链接 https://dev59.com/e2jWa4cB1Zd3GeqPrYVf#12471432。 - balexandre
现在iPhone 5已经推出了,屏幕变大了,因此您还需要在“媒体”属性中指定“device-height”。您还需要添加额外的图像。 - hitecherik
1
“iPad(Retina,横屏)SPLASHSCREEN”的设备宽度应为768而不是1536。” - Christophe Herreman
可能是因为 iPhone 5 和 6 在2013年还不存在。这很合理。应该看一下日期。 - John R Perry
显示剩余5条评论

25

这个答案提供了一种方便的方法来生成iOS目前所需的所有20个启动画面 + 最新的HTML标记以支持iOS 12.1

其中包括iPhone XR、iPhone XS Max和11英寸iPad Pro的解决方案。

背景

iOS上的Safari现在支持渐进式Web应用程序,但其实现方式与Chrome不同。它确实读取manifest文件,但忽略其中声明的图标。

相反,Safari期望一个apple-touch-startup-image标签列表。然而,官方的苹果文档列出了以下示例:

<link rel="apple-touch-startup-image" href="/launch.png">

在iOS 12.1及以后的版本中,只有一个图片不足以满足要求,这会导致误导。相反,Safari期望每个分辨率都有一个图片。

如果启动画面缺失或不正确,加载时将显示一个白屏,这看起来不专业,使(Web)应用程序感觉缓慢。


生成启动画面

在线上有一些apple-touch-startup-image生成器,但它们可能不能正常工作,或者完全忽略了Landscape模式,并且它们的命名规则也不是那么友好。这种方式更加简便。

在包含logo.png文件的目录中,以bash运行以下命令,它将生成Safari所需的20个图像(每个纵向和横向各10个分辨率):

array=( 0640x1136 0750x1334 0828x1792 1125x2436 1242x2208 1242x2688 1536x2048 1668x2224 1668x2388 2048x2732 )
for i in "${array[@]}"
do
  split=(${i//x/ })
  portrait=$i
  landscape=${split[1]}x${split[0]}
  gm convert -background white -geometry $((10#${split[0]} / 5)) "logo.png" -gravity center -extent ${portrait}  splash-portrait-${portrait}.png
  gm convert -background white -geometry $((10#${split[0]} / 5)) "logo.png" -gravity center -extent ${landscape} splash-landscape-${landscape}.png
done

这依赖于 GraphicsMagick,它是 ImageMagick 的更好替代品。在 macOS 上,使用 brew 安装非常容易,只需运行 brew install graphicsmagick

标记

以下是所有 20 个文件的 HTML 标记:

<!--
 # SPLASH SCREENS FOR iOS.
 #
 # If the splash screen is missing or incorrect, a white screen will show on load, which looks unprofessional
 # and makes the (web)app feel slow.
 #
 # Constraints:
 # - Cannot use a single image for all.
 # - The size of the image must fit that of the targeted device, else no splash screen will show.
 # - There seems to be some leeway (e.g.: pictures 40px and 60px shorter did work), but unclear how much.
 # Bottom-line: you need one splash screen per resolution and orientation.
 #
 #
 # List of devices and resolutions (AUG-2019):
 #
 #     Device              Portrait size      Landscape size     Screen size        Pixel ratio
 #     iPhone SE            640px × 1136px    1136px ×  640px     320px ×  568px    2
 #     iPhone 8             750px × 1334px    1334px ×  750px     375px ×  667px    2
 #     iPhone 7             750px × 1334px    1334px ×  750px     375px ×  667px    2
 #     iPhone 6s            750px × 1334px    1334px ×  750px     375px ×  667px    2
 #     iPhone XR            828px × 1792px    1792px ×  828px     414px ×  896px    2
 #     iPhone XS           1125px × 2436px    2436px × 1125px     375px ×  812px    3
 #     iPhone X            1125px × 2436px    2436px × 1125px     375px ×  812px    3
 #     iPhone 8 Plus       1242px × 2208px    2208px × 1242px     414px ×  736px    3
 #     iPhone 7 Plus       1242px × 2208px    2208px × 1242px     414px ×  736px    3
 #     iPhone 6s Plus      1242px × 2208px    2208px × 1242px     414px ×  736px    3
 #     iPhone XS Max       1242px × 2688px    2688px × 1242px     414px ×  896px    3
 #     9.7" iPad           1536px × 2048px    2048px × 1536px     768px × 1024px    2
 #     7.9" iPad mini 4    1536px × 2048px    2048px × 1536px     768px × 1024px    2
 #     10.5" iPad Pro      1668px × 2224px    2224px × 1668px     834px × 1112px    2
 #     11" iPad Pro        1668px × 2388px    2388px × 1668px     834px × 1194px    2
 #     12.9" iPad Pro      2048px × 2732px    2732px × 2048px    1024px × 1366px    2
 #
 # Sources:
 # - Device and resolutions (Portrait size, Landscape size) from https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/launch-screen/
 # - Screen width as measured by JavaScript's `screen.width` and `screen.height` in Simulator, except for:
 #   - 7.9" iPad mini 4 (not in Simulator): https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html
 #   - 9.7" iPad (not in Simulator): had to assume they meant iPad Pro.
 #
 #
 # Tested on the following devices, in Simulator with iOS 12.1, in both Portrait and Landscape:
 #   iPhone 5s, iPhone 6, iPhone 6 Plus, iPhone 6s, iPhone 6s Plus, iPhone 7, iPhone 7 Plus, iPhone 8,
 #   iPhone 8 Plus, iPhone SE, iPhone X, iPhone XS, iPhone XS Max, iPhone XR, iPad Air, iPad Air 2,
 #   iPad (5th generation), iPad Pro (9.7-inch), iPad Pro (12.9-inch), iPad Pro (12.9-inch) (2nd generation),
 #   iPad Pro (10.5-inch), iPad (6th generation), iPad Pro (11-inch), iPad Pro (12.9-inch) (3rd generation).
 # Everything worked fine (splash screen showing in every single case.)
 #
 # FYI:
 # - tvOS does not come with a browser. So the largest screen to care for is an iPad.)
 # - On all iPads (in Simulator), had to either Add to Home twice or restart the device to see the icon.
 #   WOULDDO Test on a real iPad.
 -->
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-portrait-0640x1136.png" media="(device-width:  320px) and (device-height:  568px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-portrait-0750x1334.png" media="(device-width:  375px) and (device-height:  667px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-portrait-0828x1792.png" media="(device-width:  414px) and (device-height:  896px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-portrait-1125x2436.png" media="(device-width:  375px) and (device-height:  812px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-portrait-1242x2208.png" media="(device-width:  414px) and (device-height:  736px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-portrait-1242x2688.png" media="(device-width:  414px) and (device-height:  896px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-portrait-1536x2048.png" media="(device-width:  768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-portrait-1668x2224.png" media="(device-width:  834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-portrait-1668x2388.png" media="(device-width:  834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-portrait-2048x2732.png" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">

<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-landscape-1136x0640.png" media="(device-width:  320px) and (device-height:  568px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-landscape-1334x0750.png" media="(device-width:  375px) and (device-height:  667px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-landscape-1792x0828.png" media="(device-width:  414px) and (device-height:  896px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-landscape-2436x1125.png" media="(device-width:  375px) and (device-height:  812px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-landscape-2208x1242.png" media="(device-width:  414px) and (device-height:  736px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-landscape-2688x1242.png" media="(device-width:  414px) and (device-height:  896px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-landscape-2048x1536.png" media="(device-width:  768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-landscape-2224x1668.png" media="(device-width:  834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-landscape-2388x1668.png" media="(device-width:  834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="/assets/site/img/splash/splash-landscape-2732x2048.png" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">

(个人而言,我会将注释放在Twig注释块中,这样就可以保留信息而不会使客户端太过冗长。)

在线上看到的一些示例使用了min-device-*,但在这种情况下,这是没有多大意义的,因为Safari期望图片具有(近似)精确的尺寸。

我看到的其他一些示例使用较短的图像(比如少40或60像素状态栏的图像)。早期版本的iOS似乎期望这种尺寸,但现在不再是这样了。


结束语

我的96% iOS用户使用iOS 12.x,所以我们不需要太在意较老的iOS版本。但如果我漏掉了什么,请让我知道。

就像一个大男孩一样,Android很高兴将应用程序的图标作为启动画面的一部分显示出来,而iOS和Safari则迫使我们进行所有这些额外的工作。要显示一个简单的启动画面需要20张图片!这太疯狂了!事情可能会变得更好,但现在就是这样。这项基本任务需要大量编码和测试。我希望它能帮助到某些人。我将尝试更新较新的分辨率。如果您发现缺少,请在评论中留言。


5
谢谢您的见解!这是我迄今看到的最完整的启动画面声明列表。尽管媒体查询在iOS上运作得非常好,但我在新的iPadOS上遇到了一个问题。似乎(orientation: landscape)部分在此处无效,因为它总是为设备显示纵向版本。然后,图像出现失真以适应宽屏模式。这是一个错误吗? - debite
3
嘿@debite,你找到解决方案来解决方向不工作的问题了吗?看起来我也遇到了同样的问题! - nickw444
@nickw444 你们中有人解决过这个问题吗?我目前正在苦恼于PWA的启动图像在横向模式下被拉伸。它只是将纵向图像缩放以适应屏幕,这当然看起来非常丑陋! - Constantin Groß
这段代码稍微有点过时了,它缺少 iPhone 12 尺寸的支持。 - Daniel Ribeiro
iPhone 12 Mini、12(和Pro)以及12 Pro Max的分辨率分别为1080x2340、1170x2532、1284x2778,像素比为3。 - josef

18

我只是想提供一些真正有效的答案组合。我们发现被选择的答案无法使用闪屏图像的视网膜版本。Pavel的答案修复了iPad的视网膜版本。以下内容已在iPhone(Retina和非Retina)和iPad(Retina和非Retina)上进行了测试。

<!-- For third-generation iPad with high-resolution Retina display: -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="apple-touch-icon-144x144-precomposed.png">
<!-- For iPhone with high-resolution Retina display: -->
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-114x114-precomposed.png">
<!-- For first- and second-generation iPad: -->
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon-72x72-precomposed.png">
<!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png">

<!-- iPhone SPLASHSCREEN-->
<link href="apple-touch-startup-image-320x460.png" media="(device-width: 320px)" rel="apple-touch-startup-image">
<!-- iPhone (Retina) SPLASHSCREEN-->
<link href="apple-touch-startup-image-640x920.png" media="(device-width: 320px) and (device-height: 460px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">
<!-- iPhone 5 (Retina) SPLASHSCREEN-->
<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 (non-Retina) (Portrait) -->
<link href="apple-touch-startup-image-768x1004.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" rel="apple-touch-startup-image" />
<!-- iPad (non-Retina) (Landscape) -->
<link href="apple-touch-startup-image-1024x748.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" rel="apple-touch-startup-image" />
<!-- iPad (Retina) (Portrait) -->
<link href="apple-touch-startup-image-1536x2008.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) and (-webkit-min-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
<!-- iPad (Retina) (Landscape) -->
<link href="apple-touch-startup-image-2048x1496.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) and (-webkit-min-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />

我不能为此承担任何功劳,但这个配置是有效的。只需复制并粘贴,确保将图像调整为其名称所指定的大小。


谢谢,这个方法可行,但只有当图片在根目录时才有效。 - Jacob Mouka
是的,说得好。我不确定将它们放在根目录中是好还是坏。我只是按照我的旧思路来处理网站图标,认为如果网站图标放在根目录中,其他新的“网站图标”也可以这样做。 - Chris
@JacobMouka 不一定在根目录下。路径是相对于HTML文件所在的目录的。 - Andrej
@Andrej 我打错了。我不是指根目录,而是指与 HTML 页面相同的目录。当链接的 href 包含任何路径时,启动图像就无法加载(但图标可以... 说不清楚)。 - Jacob Mouka
只要应用了路径,例如 href="img/apple-touch-startup-image-320x460.png" 并且相对于页面所在的路径,Works On My Machine™ 就能正常工作。在普通桌面浏览器中使用开发者工具,检查图像地址是否正确... - Eirik H

18

2
非常有用的链接,非常感谢!- 这让我成功了。 - René
我要强调的是,你必须首先在竖屏模式下启动iPad!至少在4.3.3版本中是这样。 - John B
链接已损坏。 - jorisw
找到了另一个包含相同信息的链接:https://gist.github.com/MrUzu/1044867/407e8351fc4c2326e9e656e96b8fc3df1840df07 - derickito

13

如果一个链接元素缺少了媒体属性,那么对我来说事情就不会奏效。该代码成功地在 iPhone 3G 和 iPad 上(纵向和横向模式)显示了启动图像。

<-- iPad - landscape (748x1024) -->
<link rel="apple-touch-startup-image" href="images/ipad-landscape.png"  media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" />
<-- iPad - portrait (768x1004) -->  
<link rel="apple-touch-startup-image" href="images/ipad-portrait.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" />
<-- iPhone - (320x460) -->
<link rel="apple-touch-startup-image" href="images/iphone-lowres.png" media="screen and (min-device-width: 200px) and (max-device-width: 320) and (orientation:portrait)" />

我没能在 iPhone4 (高分辨率) 上试用过,但很可能它的工作方式是相同的。


啊哈,我没想过尝试“媒体”属性!我会试一下看看效果如何。 - morgant
6
请注意,横向尺寸已经翻转! 横向图片的宽度为748,而不是1024,高度为1024。 这意味着您的横向闪屏图片应该顺时针旋转90度。 - René

4

显然,启动屏幕只在以下条件下起作用:

1)必须是设备所需的精确尺寸。 2)当应用程序启动时,设备必须处于纵向方向。 3)一些来源说只支持png格式,但现在jpg似乎也可以使用。


启动图像仅支持纵向是正确的,不幸的是这在iOS 5中仍然是如此。我真的很希望他们能在iOS 5中解决这个问题,但没有运气。 :-( - René
不用等了,我进行了更多的测试,这个错误实际上已经在iOS 5中修复了!现在,启动图像将在从主屏幕第一次或第二次启动时显示,无论您持有iPad的方向如何。只需记住LINK标签上的媒体查询!如果您没有包含它们,您将遇到奇怪的行为。 - René
为了支持“横向”方向,您还需要为其创建链接和图像。例如:对于每个可能的设备分辨率,您都有两个链接和两个图像... - Fabien Snauwaert

3

2

花了一些时间研究如何为新的iPad(Retina)制作启动画面,这是我经过测试并有效的解决方案,适用于新的iPad(Retina)的两个方向。

P.S. 在发布此文之前,我已经尝试了已有的解决方案,但它们都没有起作用。

<!-- iPad (Retina) (Portrait) -->
<link href="/img/ios/apple-touch-startup-image-1536x2008.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) and (-webkit-min-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />

<!-- iPad (Retina) (Landscape) -->
<link href="/img/ios/apple-touch-startup-image-2048x1496.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) and (-webkit-min-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />

2

对于一些人来说这可能很明显,但对我而言启动图片无法正常工作,除非我将其添加到主屏幕快捷方式中并从那里运行,并使用以下代码:

<meta name="apple-mobile-web-app-capable" content="yes" /> 

这个页面对于理解以下所有内容非常有用:http://lineandpixel.com/blog/ios-web-app-icons-and-startup-images


1
我能够为iPhone/iPad/iPhoneRetina的Web应用程序获取4个独立的启动图像的方法是通过几种方式的组合...
非Retina iPhone(320x460):
            <link rel="apple-touch-startup-image" href="startup-iphone.jpg" />

Retina iPhone(4&4S)(640x920):请使用上面发布的JavaScript技术。 http://www.paulofierro.com/archives/568/

iPad(两个方向)比较棘手。横向必须是748w x 1024h,底部为左侧。纵向必须是768w x 1004h,底部为底部。我不得不通过检测用户代理中的iPad来包含iPad标签,否则非Retina iPhone启动图像将无法加载。以下是代码...

            <?php $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad'); ?>
            <?php if ($isiPad) { ?>
            <link rel="apple-touch-startup-image" href="startup-landscape.jpg" media="only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" />
            <link rel="apple-touch-startup-image" href="startup-portrait.jpg" media="only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" />
            <?php } ?>

实现上述操作可以使我的Web应用程序(实际上是一个简单的WordPress博客网站,目前正在离线工作)在iPhone、Retina和iPad两种方向上都有启动图像。已在运行最新iOS 4的iPhone 3G、iPad和运行最新iOS 5的iPhone 4上进行了测试。

当然,你也可以通过JavaScript包含iPad代码。 lol


嗨,感谢指出肖像尺寸实际上是768x1004。我之前使用的是748x1024的图像,但无法正常工作。现在可以了。 - monzonj

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