Question

I am aware that this questions has been asked before but Im yet to find a solution. In Xcode 5 i would like to lock my application to landscape right. Here are the steps i have taken to set up the project.

(1) Create a Single View project

(2) Set Device Orientation to Landscape Right under the general settings tab

(3) Set the View Controller Orientation to Landscape in main.storyboard

(4) Add the following code to ViewController.m

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}

-(NSUInteger) supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}

(5) Add the following code to ViewController viewdidLoad

NSLog(@"frame %f %f", self.view.frame.size.width, self.view.frame.size.height);

Every time i run the app my view is 320 x 568

What do i need to set to get the view in landscape (568 x 320).

Thank you.

Was it helpful?

Solution

Even though device changed to landscape mode the width and height of the device/view is going to be same and it always returns the 320 x 568.

The difference is user viewing the device in landscape. It will not give you the change in width and height as you expected. !!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top