2013-04-04 54 views
0

我有UITableViewController其中一个选项卡上的是UINavigationViewControllerUINavigationController根视图控制器是UITableViewController,当单击单元格时,出现UIViewController,必须将其锁定在Landscape中。在UINavigationController中只处理UIViewController

我希望每个控制器都被锁定在Portrait中,除了提到的UIViewController必须锁定在Portrait之外。

我曾尝试以下:

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 

而在UIViewController中那个亩T为锁定在风景,我已经把:

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

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

但它不工作,我可以将它旋转到横向,它就会锁定在风景,但我希望它在景观自动出现。

有什么建议吗?

回答

0

我以前遇到过一个很大的问题,UITabBarController不尊重我支持的显示视图控制器的接口方向。

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

我执行UITabBarDelegate并使用didSelectItem来捕获标签开关。我不确定现在是否有更好的方法来做到这一点。

0

尝试重写方法

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

0

该方法试图阻止一些定向为特定窗口:

– application:supportedInterfaceOrientationsForWindow: 
相关问题