关闭

[[UIScreen mainScreen] bounds]和 applicationFrame

198人阅读 评论(0) 收藏 举报
分类:
 一直对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一样了)

另外:self.view.frame是读取view属性的frame属性。即xib中view的frame。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:96515次
    • 积分:2403
    • 等级:
    • 排名:第15489名
    • 原创:80篇
    • 转载:245篇
    • 译文:33篇
    • 评论:1条
    最新评论