如何强制执行子视图的横向方向,而不是父视图?

时间:2010-07-02 19:32:34

标签: iphone objective-c cocoa-touch uinavigationcontroller rotation

我有一个推动UIViewController(Child)的UINavigationController(Parent)。我知道两者都需要支持:

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

但是,我不希望父级能够旋转到横向。我该如何强制执行此操作?

更新:

我的父母已更新为:

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

但现在孩子不会轮换。

1 个答案:

答案 0 :(得分:1)

在您的父视图控制器中,您需要实现此功能。如果您尚未将用于父级的UINAvigationController子类化,请执行此操作并添加此方法。

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

在子View COntroller子类中,像你一样实现方法:

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