1、截至目前為止,主流的iOS設備屏幕有以下幾種:
--------------- iPhone ---------- -------- iPad ------------
2、iOS設備屏幕分辨率:(ppi是像素密度單位【像素/英寸】,401ppi表示每英寸上有401個像素)
ppi(pixel per inch)計算,以6Plus為例:
屏幕分辨率1920 x 1080, 屏幕尺寸5.5英寸(手機屏幕對角物理線的長度),
1920 x 1920 + 1080 x 1080 = 4852800, 開根號為:2202.907...
2202.907 / 5.5 = 400.528 ppi, 大約就是401ppi
3、iOS的三種分辨率
1)、資源分辨率:資源圖片的大小,單位是像素。
2)、設計分辨率:邏輯上的屏幕大小,單位是點。我們在Interface Builder設計器中的單位和程序代碼中的單位都是設計分辨率中的“點”。
3)、是以像素為單位的屏幕大小,所有的應用都會渲染到這個屏幕上展示給用戶。
iPhone 6 Plus和 6S Plus是最為特殊的設備,資源分辨率與屏幕分辨率的比例是1.15 : 1, 而其他的設備比例是1 : 1。不同的人群關注的分辨率也是不同的,UI設計人員主要關注的是資源分辨率,開發人員主要關注的是設計分辨率,而一般用戶主要關注的屏幕分辨率。
4、獲取設備屏幕信息
獲取當前移動設備對象:[UIDevice currentDevice]
UIDevice類所有信息
NS_CLASS_AVAILABLE_IOS(2_0) @interface UIDevice : NSObject + (UIDevice *)currentDevice; @property(nonatomic,readonly,strong) NSString *name; // e.g. "My iPhone" @property(nonatomic,readonly,strong) NSString *model; // e.g. @"iPhone", @"iPod touch" @property(nonatomic,readonly,strong) NSString *localizedModel; // localized version of model @property(nonatomic,readonly,strong) NSString *systemName; // e.g. @"iOS" @property(nonatomic,readonly,strong) NSString *systemVersion; // e.g. @"4.0" @property(nonatomic,readonly) UIDeviceOrientation orientation __TVOS_PROHIBITED; // return current device orientation. this will return UIDeviceOrientationUnknown unless device orientation notifications are being generated. @property(nullable, nonatomic,readonly,strong) NSUUID *identifierForVendor NS_AVAILABLE_IOS(6_0); // a UUID that may be used to uniquely identify the device, same across apps from a single vendor. @property(nonatomic,readonly,getter=isGeneratingDeviceOrientationNotifications) BOOL generatesDeviceOrientationNotifications __TVOS_PROHIBITED; - (void)beginGeneratingDeviceOrientationNotifications __TVOS_PROHIBITED; // nestable - (void)endGeneratingDeviceOrientationNotifications __TVOS_PROHIBITED; @property(nonatomic,getter=isBatteryMonitoringEnabled) BOOL batteryMonitoringEnabled NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED; // default is NO @property(nonatomic,readonly) UIDeviceBatteryState batteryState NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED; // UIDeviceBatteryStateUnknown if monitoring disabled @property(nonatomic,readonly) float batteryLevel NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED; // 0 .. 1.0. -1.0 if UIDeviceBatteryStateUnknown @property(nonatomic,getter=isProximityMonitoringEnabled) BOOL proximityMonitoringEnabled NS_AVAILABLE_IOS(3_0); // default is NO @property(nonatomic,readonly) BOOL proximityState NS_AVAILABLE_IOS(3_0); // always returns NO if no proximity detector @property(nonatomic,readonly,getter=isMultitaskingSupported) BOOL multitaskingSupported NS_AVAILABLE_IOS(4_0); @property(nonatomic,readonly) UIUserInterfaceIdiom userInterfaceIdiom NS_AVAILABLE_IOS(3_2); - (void)playInputClick NS_AVAILABLE_IOS(4_2); // Plays a click only if an enabling input view is on-screen and user has enabled input clicks. @end
ios移動設備類型枚舉判斷:
typedef NS_ENUM(NSInteger, UIUserInterfaceIdiom) { UIUserInterfaceIdiomUnspecified = -1, UIUserInterfaceIdiomPhone NS_ENUM_AVAILABLE_IOS(3_2), // iPhone and iPod touch style UI UIUserInterfaceIdiomPad NS_ENUM_AVAILABLE_IOS(3_2), // iPad style UI UIUserInterfaceIdiomTV NS_ENUM_AVAILABLE_IOS(9_0), // Apple TV style UI };
[UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone // 表示iPhone設備
[UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad // 表示iPad設備
[UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomTV // 表示Apple TV設備
[UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomUnspecified // 表示未知設備
//示例:詳細判斷iPhone設備類型
//詳細判斷iPhone設備信息, 區分橫屏和豎屏 if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone){ //獲取屏幕尺寸信息 CGSize screenSize = [UIScreen mainScreen].bounds.size; //豎屏情況 if (screenSize.height > screenSize.width){ if (screenSize.height == 568){ //iPhone 5/5S/5C (iPod / iPod touch) 等設備 } else if (screenSize.height == 667){ //iPone 6 / 6S 等設備 } else if (screenSize.height == 736){ //iPone 6 Plus / 6S Plus 等設備 } else{ //iPhone 4 / 4S 等設備 } } //橫屏情況 if (screenSize.width > screenSize.height){ if (screenSize.width == 568){ //iPhone 5/5S/5C (iPod / iPod touch) 等設備 } else if (screenSize.width == 667){ //iPone 6 / 6S 等設備 } else if (screenSize.width == 736){ //iPone 6 Plus / 6S Plus 等設備 } else{ //iPhone 4 / 4S 等設備 } } }
//說明:在iPad和iPhone屏幕中,一般會有狀態欄、標簽欄、導航欄(或工具欄)以及內容視圖部分,它們的尺寸也是固定的。狀態欄占20點,導航欄占44點,標簽欄占49點。
ppi(pixel per inch): 表示每英寸所包含的像素點數目,數值越高,屏幕能以更高密度顯示圖像
dpr(device pixel ratio): 設備像素比,設備像素 / 設備獨立像素,表示設備獨立像素到設備像素的轉換關系