iPad - Getting screen size in portrait and landscape
I'm using the following code to get the screen size width:
CGFloat widt开发者_运维技巧h = [UIScreen mainScreen].bounds.size.width - 100;
But its giving width as "668.0" in portrait as well as landscape. How can I get different width depending on the orientation of the device.
I ran into the same problem as you and all I could find is checking the orientation and calculate the height and width as follow:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
screenHeight = orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight ? 748 : 1004;
screenWidth = orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight ? 1024 : 768;
These size are for the the iPad obvioulsy but it could work for iPhone with the right dimensions.
Personally I think it's a bit poor but I couldn't find anything else.
Ok. In that case we can use,
CGRect viewFrame = self.view.frame; int width = viewFrame.size.width; int height = viewFrame.size.height;
CGSize winSize = [[CCDirector sharedDirector] winSize];
winSize.width will give you width and winSize.height give you height.
精彩评论