1.iPhone尺寸規格
裝置 iPhone |
寬 Width |
高 Height |
對角線 Diagonal |
邏輯解析度(point) |
Scale Factor |
裝置解析度(pixel) |
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->) 1080x1920 |
401 |
2.單位inch(英吋)
1 inch = 2.54cm = 25.4mm 3.iPhone手機寬高
上表中的寬高(width/height)為手機的物理尺寸,包括顯示屏和邊框。
以下為iPhone4s的寬高示意圖:
4.螢幕尺寸
我們通常所說的iPhone5螢幕尺寸為4英寸、iPhone6螢幕尺寸為4.7英寸,指的是顯示屏對角線的長度(diagonal)。
以下為iPhone5~6+的螢幕尺寸規格示意圖:
5.像素密度PPI
PPI(Pixel Per Inch by diagonal):表示沿著對角線,每英寸所擁有的像素(Pixel)數目。
PPI數值越高,代表顯示屏能夠以越高的密度顯示映像,即通常所說的解析度越高、顆粒感越弱。
根據勾股定理,可以得知iPhone4(s)的PPI計算公式為:
計算結果稍有出入,這是因為像素的離散採樣有鋸齒效應。 6.縮放因子(scale factor between logic point and device pixel) (1)Scale起源
早期的iPhone3GS的螢幕解析度是320*480(PPI=163),iOS繪製圖形(CGPoint/CGSize/CGRect)均以point為單位(measured in points):
1 point = 1 pixel(Point Per Inch=Pixel Per Inch=PPI)
後來在iPhone4中,同樣大小(3.5 inch)的螢幕採用了Retina顯示技術,橫、縱向方向像素密度都被放大到2倍,像素解析度提高到(320x2)x(480x2)= 960x640(PPI=326), 顯像解析度提升至iPhone3GS的4倍(1個Point被渲染成1個2x2的像素矩陣)。
但是對於開發人員來說,iOS繪製圖形的API依然沿襲point(pt,注意區分印刷行業的“磅”)為單位。在同樣的邏輯座標系下(320x480):
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)
@property(nonatomic,readonly) CGFloat scale NS_AVAILABLE_IOS(4_0);
--------------------------------------------------------------------------------
This value reflects the scale factor needed to convert from the default logical coordinate space into the device coordinate space of this screen.
The default logical coordinate space is measured using points. For standard-resolution displays, the scale factor is 1.0 and one point equals one pixel. For Retina displays, the scale factor is 2.0 and one point is represented by four pixels.
--------------------------------------------------------------------------------
為了自動適應解析度,系統會根據裝置實際解析度,自動給UIScreen.scale賦值,該屬性對開發人員唯讀。 (3)UIScreen.nativeScale
iOS8新增了nativeScale屬性:
// Native scale factor of the physical screen
@property(nonatomic,readonly) CGFloat nativeScale NS_AVAILABLE_IOS(8_0);
以下是iPhone6+下的輸出,初步看來nativeScale與scale沒有太大區別:
--------------------------------------------------------------------------------
(lldb)p (CGFloat)[[UIScreen mainScreen] scale]
(CGFloat) $1 = 3
(lldb) p(CGFloat)[[UIScreen mainScreen] nativeScale]
(CGFloat) $2 = 3
-------------------------------------------------------------------------------- (4)機型判別
在同樣的邏輯解析度下,可以通過scale參數識別是iPhone3GS還是iPhone4(s)。以下基於nativeScale參數,定義了探測機型是否為iPhone6+的宏:
--------------------------------------------------------------------------------
// not UIUserInterfaceIdiomPad
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
// detect iPhone6 Plus based on its native scale
#define IS_IPHONE_6PLUS (IS_IPHONE && [[UIScreenmainScreen] nativeScale] == 3.0f)
--------------------------------------------------------------------------------
那麼,同樣的解析度和scale,如何區分機型iPhone4與4s、iPhone5與5s呢。通過