views:

51

answers:

1

I have a UINavigationController (Parent) that is pushing a UIViewController (Child). I understand that both need to support:

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

However, I don't want the parent to be able to rotate to landscape orientation. How can I enforce this?

UPDATE:

My Parent has been updated to:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
            if (interfaceOrientation != UIInterfaceOrientationLandscapeRight ||interfaceOrientation != UIInterfaceOrientationLandscapeLeft )
          return NO;
            else
          return YES;
}

But now the child doesn't rotate.

+1  A: 

In your parent View Controller you will need to implement this. If you have not already subclassed the UINAvigationController you are using for the parent, just do that and add this method.

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (interfaceOrientation != UIInterfaceOrientationLandscape)
      return NO;
    else
      return YES;
}

In the child View COntroller subclass, implement the method like you did:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait);
}
Brad Smith
I have modified your code slightly, because UIIntefaceOrientationLandscape does not compile w/ iOS4. However, the child stops rotating.
Sheehan Alam