2012-01-18 101 views
-1

Objective-C中有一种方法可以快速获取设备屏幕的宽度和高度吗?获取设备屏幕的宽度/高度

我试着这样做:

CGRect deviceDimension = [[UIScreen mainScreen] bounds]; 

然而,在iPad的风景模式下,它仍然给我768的宽度和1024的高度。任何其他想法?或者我必须使用宏?基本上我试图找到一种方式来代替下面的宏:

#ifdef IPHONE 

#define SCREEN_WIDTH_PORTRAIT 320 
#define SCREEN_WIDTH_LANDSCAPE 480 

#else 

#define SCREEN_WIDTH_PORTRAIT 768 
#define SCREEN_WIDTH_LANDSCAPE 1024 

#endif 
+0

参见:http://stackoverflow.com/questions/3655104/iphone-ipad-how-to-get-screen-宽度编程方式 – 2012-01-18 21:22:36

+0

可能的重复[如何获取方向相关的高度和宽度的屏幕?](http://stackoverflow.com/questions/7905432/how-to-get-orientation-dependent-height-and-width屏幕) – 2012-01-18 21:44:28

回答

2

再加上

if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) { } 

从1024×768 768×1024分辨。

0

查看下面Richard J. Ross III的评论。

你可以做这样的:

- (CGSize)screenSizeWithRotation 
{ 
    return CGSizeMake(CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)); 
} 

+0

或者只是使用'self.view.bounds.size' ... – 2012-01-18 21:30:47

+1

@ RichardJ.RossIII哦,是的。当然。忽略我的答案。 – simonbs 2012-01-18 21:37:57

+0

,只给我什么当前视图控制器的大小是... – adit 2012-01-18 23:01:36