Search code examples
ioscocoa-touchuiinterfaceorientation

UIInterfaceOrientation Xcode


I would like my app to support PortraitUpSideDown orientation. I have changed the info.p list to reflect this and tried to implement the change on one view as a test

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
    return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
    return YES;

}

But the view does not respond. Do I need to implement this on all views before the app responds? Is there a Xib setting I need to change?


Solution

  • If you would like to support both landscape orientations, try the following:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
    }
    

    Or:

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

    Or somethings that looks like what you were trying to write:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        if (interfaceOrientation == UIInterfaceOrientationPortrait) {
            return YES;
        }
        if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
            return YES;
        }
        return NO;
    }