0

I have UITableViewController in which on one tab is UINavigationViewController. UINavigationController root view controller is UITableViewController, and when clicked on cell, UIViewController appears which has to be locked in Landscape.

I want every Controller to be locked in Portrait, except the mentioned UIViewController that must be locked in Portrait.

I have tried the following:

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

And in UIViewController that must be locked in to Landscape, I have put:

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

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

But it doesn't work, I can rotate it to Landscape and it will stay locked in Landscape, but I want it to appear automatically in Landscape.

Any suggestions?

4

3 回答 3

0

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

I solved the problem by sub-classing UITabBarControllerand capturing whenever an item was selected. 然后我会自己调用视图控制器,询问它支持的方向是什么,并在需要时自己强制旋转。我还会在旋转时调用选定的视图控制器来设置/更改我支持的方向。

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

于 2013-04-04T16:49:05.937 回答
0

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

– application:supportedInterfaceOrientationsForWindow:
于 2014-03-13T10:45:27.287 回答
0

尝试覆盖方法

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

于 2013-07-24T05:24:07.923 回答