Sheehan Alam
Sheehan Alam

Reputation: 60869

How to enforce landscape orientation for child view, but not parent view?

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.

Upvotes: 0

Views: 576

Answers (1)

Brad The App Guy
Brad The App Guy

Reputation: 16275

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);
}

Upvotes: 1

Related Questions