• ios设备的尺寸不大敏感[UIScreen mainScreen


    一直对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)

    测试调用:

    1
    2
    3
    4
    5
    NSLog(@"[[UIScreen mainScreen] bounds]");
     PrintRect([[UIScreen mainScreen] bounds]);
         
     NSLog(@"[[UIScreen mainScreen] applicationFrame]");
     PrintRect([[UIScreen mainScreen]applicationFrame]);

    测试结果:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    //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.000000
    2013-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.000000
    2013-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.000000
    2013-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.000000
    2013-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.000000
    2015-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 6
    2015-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.000000
    2015-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一样了)

  • 相关阅读:
    js获取Session问题 dodo
    复制一个datatable的指定行到另外一个datatable dodo
    sqlserver数据库备份与还原语句 dodo
    net软件测试实战技术大全 dodo
    AJAX 浏览器支持 dodo
    使用 vs2005进行负载测试 dodo
    sql使用in批量删除 dodo
    各种浏览器兼容存在的方法:Xenocode Browser Sandbox dodo
    C#调用Windows API函数 dodo
    ewebeditor在ie8下报错 dodo
  • 原文地址:https://www.cnblogs.com/shupaopao/p/4323541.html
Copyright © 2020-2023  润新知