今天同事寫(xiě)代碼的時(shí)候物赶,發(fā)現(xiàn)[UIScreen mainScreen].bounds取出的值和預(yù)想的不一樣橡庞,搞了好長(zhǎng)時(shí)間较坛,才發(fā)現(xiàn)了當(dāng)前手機(jī)使用的放大模式(設(shè)置->顯示與亮度->放大標(biāo)準(zhǔn),4.7寸及以上才可以設(shè)置)扒最,使用了放大模式之后[UIScreen mainScreen].bounds取出的值就有問(wèn)題了丑勤。
下面是在不同機(jī)型的不同模式下打印的bounds、nativeBounds吧趣、currentMode的值
- IPhone 6Plus 標(biāo)準(zhǔn)
(lldb) po [UIScreen mainScreen].bounds
(origin = (x = 0, y = 0), size = (width = 414, height = 736))
(lldb) po [UIScreen mainScreen].nativeBounds
(origin = (x = 0, y = 0), size = (width = 1080, height = 1920))
(lldb) po [UIScreen mainScreen].currentMode
<UIScreenMode: 0x2823fb7a0; size = 1242.000000 x 2208.000000>
- IPhone 6Plus 放大
(lldb) po [UIScreen mainScreen].bounds
(origin = (x = 0, y = 0), size = (width = 375, height = 667))
(lldb) po [UIScreen mainScreen].nativeBounds
(origin = (x = 0, y = 0), size = (width = 1080, height = 1920))
(lldb) po [UIScreen mainScreen].currentMode
<UIScreenMode: 0x2803d6700; size = 1125.000000 x 2001.000000>
- IPhone 6 標(biāo)準(zhǔn)
(lldb) po [UIScreen mainScreen].bounds
(origin = (x = 0, y = 0), size = (width = 375, height = 667))
(lldb) po [UIScreen mainScreen].nativeBounds
(origin = (x = 0, y = 0), size = (width = 750, height = 1334))
(lldb) po [UIScreen mainScreen].currentMode
<UIScreenMode: 0x109edd6c0; size = 750.000000 x 1334.000000>
- IPhone 6 放大
(lldb) po [UIScreen mainScreen].bounds
(origin = (x = 0, y = 0), size = (width = 320, height = 568))
(lldb) po [UIScreen mainScreen].nativeBounds
(origin = (x = 0, y = 0), size = (width = 750, height = 1334))
(lldb) po [UIScreen mainScreen].currentMode
<UIScreenMode: 0x113b1f6f0; size = 640.000000 x 1136.000000>
- iPhone 5
(lldb) po [UIScreen mainScreen].bounds
(origin = (x = 0, y = 0), size = (width = 320, height = 568))
(lldb) po [UIScreen mainScreen].nativeBounds
(origin = (x = 0, y = 0), size = (width = 640, height = 1136))
(lldb) po [UIScreen mainScreen].currentMode
<UIScreenMode: 0xc57a1b0; size = 640.000000 x 1136.000000>
可以發(fā)現(xiàn)
- IPhone6Plus標(biāo)準(zhǔn)的值的bounds是正確的法竞,nativeBounds與IPhone6Plus放大的值是一樣的,同時(shí)他們的currentMode的值是他們對(duì)應(yīng)的bounds的值 * 3的結(jié)果强挫。
- IPhone6標(biāo)準(zhǔn)的值的bounds是正確的岔霸,nativeBounds與IPhone6放大的值是一樣的,同時(shí)他們的currentMode的值是他們對(duì)應(yīng)的bounds的值 * 2的結(jié)果俯渤。
- IPhone6Plus放大的值的bounds等于IPhone6標(biāo)準(zhǔn)的值呆细,IPhone6放大的值的bounds等于IPhone5的值
結(jié)論
在平時(shí)開(kāi)發(fā)的過(guò)程當(dāng)中,這些因素可以基本忽略不計(jì)八匠,官方文檔也是不鼓勵(lì)去糾結(jié)這些絮爷,不過(guò)也要注意一下诡曙,如果你的代碼中有通過(guò)[UIScreen mainScreen].bounds.size.height 的值去判斷當(dāng)前屏幕尺寸的代碼,這是不可取的略水,用nativeBounds去代替這個(gè)值。