开发者

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 != UIInterfaceOrient开发者_JAVA技巧ationLandscapeRight ||interfaceOrientation != UIInterfaceOrientationLandscapeLeft )
          return NO;
            else
          return YES;
}

But now the child doesn't rotate.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜