iOS中的safri瀏覽器可以將一個網頁添加到桌面,當做一個獨立的應用運行。
當然,這里我們不討論怎么去做一個webApp,這需要html5的相關知識和開發經驗。
這里我們只講webApp添加桌面后到啟動的相關細節。
全屏顯示:
<meta name="apple-mobile-web-app-capable" content="yes" />
系統頂欄的顏色(黑色和白色):
<meta name="apple-mobile-app-status-bar-style" content="white" /> <meta name="apple-mobile-app-status-bar-style" content="black" />
桌面程圖標(如果不設置,則圖標會顯示網頁的截圖):
<link rel="apple-touch-icon" href="icon.png" />
但是,iOS會自作多情的給這個圖標加上高光,如果想圖標不被高光,可以這樣:
<link rel="apple-touch-icon-precomposed" href="icon.png" />
如果想給不同的設備匹配不同的icon,可以加上size屬性:
<link rel="apple-touch-icon" size="72x72" href="icon-ipad.png" /> <link rel="apple-touch-icon" size="114x114" href="icon-iphone4.png" />
程序啟動的過程中,需要指定啟動畫面,否則,白屏或者截圖是讓人很不愉悅的。
iOS有ipad和iPhone/ipod touch之分。
ipad的啟動畫面是橫豎屏分開的,畫面的尺寸必須是1024*768、768*1024。
iPhone和ipod touch雖然都是豎屏的,但是卻有Retina屏幕和非Retina屏幕之分;另外它們啟動畫面的尺寸並不是屏幕的大小,而是(屏幕寬度)*(屏幕高度-20)。也就是說,非Retina的尺寸為320*460,Retina屏幕的尺寸為640*920。
引入啟動畫面是支持媒體查詢的。
因此,可以通過media query給ipad的橫豎屏引入不同的圖:
<link rel="apple-touch-start-image" href="landScape.png" madia="screen and (min-device-width:481px) and (max-device-width:1024px) and (orientation:landscape)" /> <link rel="apple-touch-start-image" href="portait.png" madia="screen and (min-device-width:481px) and (max-device-width:1024px) and (orientation:portait)" />
但是媒體查詢卻搞不定Retina屏幕,所以通過js來hack:
首先,給普通的分辨率引入320*460的圖片:
<link rel="apple-touch-start-image" href="start.png"media="screen and (max-device-weidth:320px)" /> Retina屏幕js:
if((app.device.type === "iPhone" || app.device.type === "iPod") && app.device.version >= '5' && window.devicePixelRatio >= 2){ $('head').append($('<link rel="apple-touch-startup-image" href="start-640-920.png" />')); }