iPhone屏幕尺寸、分辨率及适配

1.iPhone尺寸规格

iPhone

Width

Height对角线

Diagonal逻辑分辨率(point)

Scale Factor

PPI

3GS

2.4 inches (62.1 mm)

4.5 inches (115.5 mm)

3.5-inch

320x480

@1x

320x480

163

4(s)

2.31 inches (58.6 mm)

4.5 inches (115.2 mm)

3.5-inch

320x480

@2x

640x960

326

5c

2.33 inches (59.2 mm)

4.90 inches (124.4 mm)

4-inch

320x568

@2x

640x1136

326

5(s)

2.31 inches (58.6 mm)

4.87 inches (123.8 mm)

4-inch

320x568

@2x

640x1136

326

6

2.64 inches (67.0 mm)

5.44 inches (138.1 mm)

4.7-inch

375x667

@2x

750x1334

326

6+

3.06 inches (77.8 mm)

6.22 inches (158.1 mm)

5.5-inch

414x736

@3x

(1242x2208->)

1080x1920401

2.单位inch（英吋）

1 inch = 2.54cm = 25.4mm

3.iPhone手机宽高

4.屏幕尺寸

5.像素密度PPI

PPI（Pixel Per Inch by diagonal）：表示沿着对角线，每英寸所拥有的像素（Pixel）数目。

PPI数值越高，代表显示屏能够以越高的密度显示图像，即通常所说的分辨率越高、颗粒感越弱。

6.缩放因子scale factorbetween logic point and device pixel）

（1）Scale起源

1 point = 1 pixel（Point Per Inch=Pixel Per Inch=PPI）

1 point = scale*pixel（在iPhone4~6中，缩放因子scale=2；在iPhone6+中，缩放因子scale=3）。

scale=绝对长度比point/pixel）=单位长度内的数量比pixel/point）

（2）UIScreen.scale

UIScreen.h中定义了该属性：

// The natural scale factor associated with the screen.(read-only)

--------------------------------------------------------------------------------

This value reflects the scale factor needed to convert from the defaultlogical coordinate spaceinto thedevice

coordinate spaceof this screen.

The default logical coordinate space is measured usingpoints. Forstandard-resolutiondisplays, the scale factor is 1.0 andone point equals one pixel. ForRetinadisplays, the scale factor is 2.0 andone point is represented by four pixels.

--------------------------------------------------------------------------------

（3）UIScreen.nativeScale

iOS8新增了nativeScale属性：

// Native scale factor of the physical screen

--------------------------------------------------------------------------------

(lldb)p (CGFloat)[[UIScreen mainScreen] scale]

(CGFloat) \$1 = 3

(lldb) p(CGFloat)[[UIScreen mainScreen] nativeScale]

(CGFloat) \$2 = 3

--------------------------------------------------------------------------------

（4）机型判别

--------------------------------------------------------------------------------

#defineIS_IPHONE(UI_USER_INTERFACE_IDIOM() ==UIUserInterfaceIdiomPhone)

// detect iPhone6 Plus based on its native scale

#defineIS_IPHONE_6PLUS(IS_IPHONE && [[UIScreenmainScreen] nativeScale] == 3.0f)

--------------------------------------------------------------------------------

8.@2x/@3x以及高倍图适配

（1）@2x

@2xmeans the same “double”retina resolution that we’veseen on all iOS devices with retina

displays to date, where each virtual pointin the user interface is represented bytwophysical pixels on thedisplayin each dimension, horizontal and vertical.

iPhone3GS时代，我们为一个应用提供图标（或按钮提供贴图），只需要icon.png。针对现在的iPhone4~6 Retina显示屏，需要制作额外的@2x高分辨率版本。

iPhone4~6中，scale=2，则需要100×100pixel（logical

image.size=50x50point，乘以image.scale=dimensions in

pixels），并且命名为icon@2x.png。

（2）@3x

@3xmeans a new “triple” retina resolution, where eachuser interface point is represented

bythreedisplay pixels. A single @2x pointis a 2 × 2 square of 4 pixels; an @3x point is a 3 × 3 square of 9 pixels.”

iPhone6+在实际渲染时，downsampling/1.15（1242x2208->1080x1920），准确的讲，应该是@2.46x。苹果为方便开发者用的是@3x的素材，然后再缩放到@2.46x上。

（3）高倍图文件命名

<1>+imageNamed：该方法使用系统缓存，适合表视图重复加载图像的情形。同时该API根据UIScreen的scale，自动查找包含对应高倍图后缀名（@2x）的文件，如果没找到设置默认image.scale=1.0。因此，使用该方法，无需特意指定高倍图后缀。在实际运行时，系统如果发现当前设备是Retina屏（scale=2），会自动寻找"*@2x.png"命名格式的图片，加载针对Retina屏的图片素材，否则会失真。

<2>+imageWithContentsOfFile/+imageWithData:(scale:)/-initWithContentsOfFile:/-initWithData:(scale:)

<3>目前，适配iPhone6+时，除了一些铺满全屏的大图（LogoIcon、LaunchImage）需提供三倍图，其他的小图仍可沿用原有的二倍图自适应拉伸。

9.Screen Bounds&Application Frame

（1）UIScreen.bounds

// Bounds of entire screen in points（本地坐标系，起点为[0,0]）

--------------------------------------------------------------------------------

//考虑转屏的影响，按照实际屏幕方向（UIDeviceOrientation）的宽高

#defineSCREEN_WIDTH([UIScreenmainScreen].bounds.size.width)

#defineSCREEN_HEIGHT([UIScreenmainScreen].bounds.size.height)

#defineSTATUSBAR_HEIGHT([UIApplicationsharedApplication].statusBarFrame.size.height)

//不考虑转屏的影响，只取竖屏（UIDeviceOrientationPortrait）的宽高

#defineSCREEN_WIDTHMIN([UIScreenmainScreen].bounds.size.width,

[UIScreenmainScreen].bounds.size.height)

#defineSCREEN_HEIGHTMAX([UIScreenmainScreen].bounds.size.height,

[UIScreenmainScreen].bounds.size.width)

#defineSTATUSBAR_HEIGHTMIN([UIApplicationsharedApplication].statusBarFrame.size.width,

[UIApplicationsharedApplication].statusBarFrame.size.height)

--------------------------------------------------------------------------------

（2）UIScreen.nativeBounds

iOS8新增了nativeBounds属性，输出竖屏像素级分辨率：

// The bounding rectangle of the physical screen,measured inpixels. (read-only)

// This rectangle is based on the device in a portrait-up orientation. This value does not change as the device rotates.

--------------------------------------------------------------------------------

(lldb) poNSStringFromCGRect([(UIScreen*)[UIScreen mainScreen] bounds])

{{0, 0}, {414, 736}}

(lldb) poNSStringFromCGRect([(UIScreen*)[UIScreen mainScreen] nativeBounds])

{{0, 0}, {1242, 2208}}

--------------------------------------------------------------------------------

（3）UIScreen.applicationFrame

// Frame of application screen area in points (i.e.entire screenminusstatus bar if visible)

// bounds除去系统状态栏

--------------------------------------------------------------------------------

// APPFRAME_WIDTH=SCREEN_WIDTH

#defineAPPFRAME_WIDTH([UIScreen

mainScreen].applicationFrame.size.width)

// APPFRAME_HEIGHT=SCREEN_HEIGHT-STATUSBAR_HEIGHT

//注意：横屏（UIDeviceOrientationLandscape）时，iOS8默认隐藏状态栏，此时APPFRAME_HEIGHT=SCREEN_HEIGHT

#defineAPPFRAME_HEIGHT([UIScreen mainScreen].applicationFrame.size.height)

--------------------------------------------------------------------------------

（4）bounds和frame的区别

10.机型尺寸适配Screen

（@3x）；从屏幕尺寸角度来看，需要重新对UI元素尺寸和布局进行适配，以期视觉协调。

（1）按宽度适配

iPhone4(s)：分辨率960*640，高宽比1.5

iPhone5(s)：分辨率1136*640，高宽比1.775

iPhone6：分辨率1334*750，高宽比1.779

iPhone6+：分辨率1920*1080，高宽比1.778

fitScreenWidth= width*(SCREEN_WIDTH/320)

（2）按高度适配

fitScreenHeight= height*(SCREEN_HEIGHT/568)

Hotspot: * Connection"，纵向会下压20pt，[UIApplication sharedApplication].statusBarFrame高度变为40pt；当所有连接都断开时，热点栏消失，纵向高度恢复正常为20pt。详情可参考《iPhone/iOS开启个人热点的纵向适配小结》。

（3）按字体适配

11.UI相对布局

12.DEPRECATED API适配

（1）UILineBreakMode->NSLineBreakMode

（2）UITextAlignment->NSTextAlignment

（3）sizeWithFont:->boundingRectWithSize:

（4）stretchableImageWithLeftCapWidth:topCapHeight:->resizableImageWithCapInsets:

（5）...

iOS8适配须知

《iOS界面适配()()()》