【问题标题】:Landscape only UIViewController in UINavigationControllerUINavigationController 中的仅横向 UIViewController
【发布时间】:2013-04-04 15:44:57
【问题描述】:

我有UITableViewController,其中一个选项卡上是UINavigationViewControllerUINavigationController根视图控制器为UITableViewController,点击单元格时出现UIViewController,需要锁定在Landscape中。

我希望每个 Controller 都锁定在 Portrait,除了提到的必须锁定在 PortraitUIViewController

我尝试了以下方法:

CustomTabBarController.m:

#import "CustomTabBarController.h"

@implementation CustomTabBarController

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // You do not need this method if you are not supporting earlier iOS Versions
    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

- (BOOL)shouldAutorotate{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
    return [self.selectedViewController supportedInterfaceOrientations];
}

@end

CustomNavigationController.h:

#import "CustomNavigationController.h"

@implementation CustomNavigationController

-(NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate
{
    return YES;
}

@end

在必须锁定到 Landscape 的 UIViewController 中,我放了:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

但它不起作用,我可以将它旋转到横向,它会保持锁定在横向,但我希望它自动出现在横向中。

有什么建议吗?

【问题讨论】:

    标签: iphone ios uiviewcontroller orientation landscape


    【解决方案1】:

    过去我遇到了一个大问题,UITabBarController 不尊重我支持的显示视图控制器的界面方向。

    我通过子类UITabBarController 解决了这个问题,并在选择项目时捕获。然后我会自己调用视图控制器,询问它支持的方向是什么,并在需要时自己强制旋转。我还会在旋转时调用选定的视图控制器来设置/更改我支持的方向。

    我实现了UITabBarDelegate 并使用didSelectItem 来捕获选项卡开关。我不确定现在是否有更好的方法。

    【讨论】:

      【解决方案2】:

      尝试重写方法

      - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

      【讨论】:

        【解决方案3】:

        尝试使用该方法阻止特定窗口的某些方向:

        – application:supportedInterfaceOrientationsForWindow:
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-04-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-11-24
          • 2015-06-23
          相关资源
          最近更新 更多