I don't know is this happening because of simulators or the new XCode, but I read that there is a solution for this. The solution is using a viewWillLayoutSubviews for creating the scene instead of viewDidLoad.
So I tried that, but that doesn't work. In landscape mode for iPad returned dimensions are always 768x1024 instead of 1024x768. Earlier, in XCode 5, viewWillLayoutSubviews did the trick. But now in XCode 6 I can't get that behaviour. I have this problem on 7.1 simulators. 8.0 simulators are just fine, and showing dimensions correctly.
Here is my GameSceneViewController.
@implementation GameViewController
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
skView.showsDrawCount = YES;
skView.showsPhysics = NO;
if(!skView.scene){
// Create and configure the scene.
GameScene * scene = [GameScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
}
- (BOOL)shouldAutorotate{return YES;}
- (NSUInteger)supportedInterfaceOrientations{return UIInterfaceOrientationMaskLandscape;}
- (void)didReceiveMemoryWarning{[super didReceiveMemoryWarning];}
- (BOOL)prefersStatusBarHidden {return YES;}
@end
In the info.plist file for supported interface oorientations are two items: UIInterfaceOrientationLandscapeRight
and UIInterfaceOrientationLandscapeLeft
How can I get the correct sizes of a width and height in iPad landscape mode?
The screen size will always be the same regardless of device orientation. The same with the key window size. The view controllers are the ones that rotate inside the window. So you either rotate your view if you're adding it to the window directly or simply add it to the root view controller, which will have a correct size.
For example:
UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow;
UIViewController* rootController = keyWindow.rootViewController;
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CGSize windowSize = keyWindow.bounds.size;
CGSize rootControllerSize = rootController.view.frame.size;
CGSize rootControllerBoundsSize = rootController.view.bounds.size;
CGAffineTransform rootTransform = rootController.view.transform;
NSLog(@"Screen size: %@", NSStringFromCGSize(screenSize));
NSLog(@"Window size: %@", NSStringFromCGSize(windowSize));
NSLog(@"RootController frame size: %@", NSStringFromCGSize(rootControllerSize));
NSLog(@"RootController bounds size: %@", NSStringFromCGSize(rootControllerBoundsSize));
NSLog(@"RootController transform: %@", NSStringFromCGAffineTransform(rootTransform));
if executed in landscape will print the following:
Screen size: {768, 1024}
Window size: {768, 1024}
RootController frame size: {768, 1024}
RootController bounds size: {1024, 768}
RootController transform: [0, 1, -1, 0, 0, 0]
The key here is the transform that it's applied to the root UIViewController
when the device is rotated.
To obtain the screen size taking into account the device rotation you can use the root controller bounds size.