虽然没有能力开发Native App,但仍是能够利用iOS中Safari浏览器的特性小小的折腾一下,作一个伪Web App知足下小小的虚荣心的。web
既然是在iOS中的Safari折腾的,那么代码中利用到的也基本上都是Safari的私有属性。浏览器
添加图标到主屏幕是Web App的第一步:app
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="icon-57.png">测试
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="icon-72.png">动画
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="icon-114.png">spa
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="icon-144.png">scala
添加图标到屏幕里的有两种属性值apple-touch-icon和apple-touch-icon-precomposed,区别就在因而否会应用iOS中自动给图标添加的那层高光。orm
因为iPhone以及iPad都有两种分辨率的设备存在,图标的尺寸就须要作4个:144×144(iPad Retina)、72×72(iPad)、114×114(iPhone Retina)、57×57(iPhone)。图片
能够使用sizes尺寸来告诉设备该调用哪一个图标。开发
有了图标还不够像,还须要加上启动画面:
<link rel="apple-touch-startup-image" sizes="2048x1496" href="icon-2048x1496.png" media="screen and (min-device-width:481px) and (max-device-width:1024px) and (orientation:landscape) and (-webkit-min-device-pixel-ratio: 2)">
<link rel="apple-touch-startup-image" sizes="1536x2008" href="icon-1536x2008.png" media="screen and (min-device-width:481px) and (max-device-width:1024px) and (orientation:portrait) and (-webkit-min-device-pixel-ratio: 2)">
<link rel="apple-touch-startup-image" sizes="640x920" href="icon-640x920.png" media="screen and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)">
<link rel="apple-touch-startup-image" sizes="320x460" href="icon-320x460.png" media="screen and (max-device-width: 320)">
apple-touch-startup-image是用来标示启动画面的,但它不像apple-touch-icon能够指定sizes来告诉设备该使用哪一个图片(也有一种说法是在iOS5中已经支持sizes识别了,但没有测试成功),因此只能经过media里的设备分辨率的判断值来识别,而iPhone Retina的分辨率值界于取值之间,因此须要经过webkit的私有属性-webkit-min-device-pixel-ratio:2来鉴别像素密度以进行识别。
启动画面的图片尺寸并不是彻底等于设备的尺寸,好比iPad2的尺寸是1024×768,但它的启动画面尺寸横向是1024×748,竖向尺寸是768×1004,由于须要减去系统状栏的高度20px,而使用的Retina屏幕的iPhone4以及iPad3则须要减去状态栏的高度40px。
Web App运行起来要像Native App,那么就要去掉Safari的一些默认控件,好比地址栏、状态栏之类的。
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1.0, maximum-scale=1, user-scalable=no">
apple-mobile-web-app-capable是用来定义应用全屏展现的;在定义了apple-mobile-web-app-capable的前提下,设置状态栏的属性值apple-mobile-web-app-status-bar-style才有效;format-detection的值用于启用或禁用自动检测在网页中可能出现的电话号码;
viewport并不是Safari的私有属性,width用于指定宽度,initial-scale指定初始化的缩略比例,minimum-scale指定缩小的比例,而maximum-scale则是放大的比例,固然这些缩放都取决于user-scalable——决定用户是否能缩放页面。