ios裝置的尺寸不大敏感[UIScreen mainScreen

來源:互聯網
上載者:User

標籤:

一直對ios裝置的尺寸不大敏感,搞不清[[UIScreen mainScreen] bounds] 和[UIScreen mainScreen] applicationFrame]的區別,故總是心虛,現掃盲下:

定義一個宏:

?
1 #define PrintRect(frame) NSLog(@"X:%f,Y:%f,W:%f,H:%f",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height)

 

測試調用:

?
12345 NSLog(@"[[UIScreen mainScreen] bounds]"); PrintRect([[UIScreen mainScreen] bounds]);      NSLog(@"[[UIScreen mainScreen] applicationFrame]"); PrintRect([[UIScreen mainScreen]applicationFrame]);

 

測試結果:

?
1234567891011121314151617181920212223242526272829303132333435363738394041424344 //Ipad4 retain:2013-07-17 10:08:39.094 IpadSize[191:907] [[UIScreen mainScreen] bounds]2013-07-17 10:08:39.097 IpadSize[191:907] X:0.000000,Y:0.000000,W:768.000000,H:1024.000000 2013-07-17 10:08:39.098 IpadSize[191:907] [[UIScreen mainScreen] applicationFrame]2013-07-17 10:08:39.099 IpadSize[191:907] X:0.000000,Y:20.000000,W:768.000000,H:1004.000000 //ipad normal:2013-07-17 10:19:09.886 IpadSize[1223:11303] [[UIScreen mainScreen] bounds]2013-07-17 10:19:09.887 IpadSize[1223:11303] X:0.000000,Y:0.000000,W:768.000000,H:1024.0000002013-07-17 10:19:09.887 IpadSize[1223:11303] [[UIScreen mainScreen] applicationFrame]2013-07-17 10:19:09.888 IpadSize[1223:11303] X:0.000000,Y:20.000000,W:768.000000,H:1004.000000 //iphone:2013-07-17 10:15:39.372 IpadSize[1005:11303] [[UIScreen mainScreen] bounds]2013-07-17 10:15:39.373 IpadSize[1005:11303] X:0.000000,Y:0.000000,W:320.000000,H:480.0000002013-07-17 10:15:39.374 IpadSize[1005:11303] [[UIScreen mainScreen] applicationFrame]2013-07-17 10:15:39.374 IpadSize[1005:11303] X:0.000000,Y:20.000000,W:320.000000,H:460.000000   //iphone 3.5 retain:2013-07-17 10:16:34.145 IpadSize[1043:11303] [[UIScreen mainScreen] bounds]2013-07-17 10:16:34.146 IpadSize[1043:11303] X:0.000000,Y:0.000000,W:320.000000,H:480.0000002013-07-17 10:16:34.147 IpadSize[1043:11303] [[UIScreen mainScreen] applicationFrame]2013-07-17 10:16:34.147 IpadSize[1043:11303] X:0.000000,Y:20.000000,W:320.000000,H:460.000000 //iphone 4 retain:2013-07-17 10:17:26.562 IpadSize[1083:11303] [[UIScreen mainScreen] bounds]2013-07-17 10:17:26.563 IpadSize[1083:11303] X:0.000000,Y:0.000000,W:320.000000,H:568.0000002013-07-17 10:17:26.564 IpadSize[1083:11303] [[UIScreen mainScreen] applicationFrame]2013-07-17 10:17:26.564 IpadSize[1083:11303] X:0.000000,Y:20.000000,W:320.000000,H:548.000000 //IPHONE 6 Plus:2015-01-09 19:59:57.905 TripPlusMeIphone[1183:230595] [[UIScreen mainScreen] bounds]2015-01-09 19:59:57.905 TripPlusMeIphone[1183:230595] X:0.000000,Y:0.000000,W:414.000000,H:736.0000002015-01-09 19:59:57.905 TripPlusMeIphone[1183:230595] [[UIScreen mainScreen] applicationFrame]2015-01-09 19:59:57.905 TripPlusMeIphone[1183:230595] X:0.000000,Y:0.000000,W:414.000000,H:736.000000 //iphone 62015-01-09 20:02:32.910 TripPlusMeIphone[87512:1855595] [[UIScreen mainScreen] bounds]2015-01-09 20:02:32.911 TripPlusMeIphone[87512:1855595] X:0.000000,Y:0.000000,W:375.000000,H:667.0000002015-01-09 20:02:32.911 TripPlusMeIphone[87512:1855595] [[UIScreen mainScreen] applicationFrame]2015-01-09 20:02:32.911 TripPlusMeIphone[87512:1855595] X:0.000000,Y:0.000000,W:375.000000,H:667.000000

 

從日誌輸出可以看到,bounds就是螢幕的全部地區,applicationFrame就是app顯示的地區,不包含狀態列(高度20,如果狀態列隱藏的話,那麼,這個結果就和bounds一樣了)

ios裝置的尺寸不大敏感[UIScreen mainScreen

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.