【问题标题】:How to enforce landscape orientation for child view, but not parent view?如何为子视图强制横向,而不是父视图?
【发布时间】:2010-07-02 19:32:34
【问题描述】:

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

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

但现在孩子没有旋转。

【问题讨论】:

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


    【解决方案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);
    }
    

    【讨论】:

    • 我已经稍微修改了你的代码,因为 UIIntefaceOrientationLandscape 不能用 iOS4 编译。但是,孩子停止旋转。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    相关资源
    最近更新 更多