Search code examples
xcodeniblandscape

XCODE Storyboards, landscape view


I have created an app using Storyboards, and have designed it to be landscape.

In the view controller.m file I have placed the following code:

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

I have tried a million variants of that code as well, all with the same result.

In addition, I have changed the supported orientations in the info.plist, and of course made the storyboards landscape as well. However, when I simulate, the initial launch is in landscape, then the sub navigation windows snap back to portrait. So, my question is, how can I override the portrait default when using storyboards (meaning, no nib)? I am new to making apps - so it's probably something oh so simple for you guys and your huge brains, so I figured it was worth asking. I am ready to accept your laughter and pointed fingers for my newbish behavior. =]


Solution

  • Did you associate your custom controller class (where you have override the shouldAutorotateToInterfaceOrientation method) to your scene in storyboard? If not you need to make sure you are referencing this class in the custom class section of the identity inspector of your scene in your storyboard editor.

    I like to use this instruction in the shouldAutorotateToInterfaceOrientation method to make sure only landscape is supported:

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

    You can take a look to this tutorial as an introduction to storyboard in ios5 : http://blogs.interknowlogy.com/2012/01/16/introduction-to-ios-5-storyboards-part-1/