2012-11-11 40 views
4

我正在使用故事板,我有UITabBarController嵌入UINavigationController。 我推一个视图控制器,然后从这个视图控制器我提出了一个UIViewController MODAL UINavigationController。模态UINavigationController - 我不能停止旋转

问题是,模态视图控制器可以旋转,当我的视图之前的模态视图不能。 如何阻止Modal导航控制器允许任何旋转?

我曾尝试加入:

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

感谢

+0

类别?使用支持的界面方向。 – Majster

+0

我对其他视图使用其他方向,我只需要限制这个视图。 – Darren

+0

@达伦在这里,你应该去相同... http://stackoverflow.com/questions/13023936/orientation-issue-in-ios-6/13024015#13024015。你可能会得到任何想法相同 – Kamarshad

回答

5

尝试你试过编辑info.plist中的UINavigationController

@implementation UINavigationController (Rotation_IOS6) 

-(BOOL)shouldAutorotate 
{ 
    return [[self.viewControllers lastObject] shouldAutorotate]; 
} 

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
} 
+4

非常危险 - 一个类将取代方法的初始实现,你不知道在UINavigationController的方法中应用了什么其他的逻辑,一个更好的解决方案是创建你自己的'UIViewController'的抽象子类。 (例如称为MyAbstractViewController ')在你的答案中包含方法,并且每当你需要一个视图时,不要将'UIViewController',子类MyAbstractViewController代替。 – deanWombourne

+3

这工作。我使用这些方法创建了一个UINavigationController子类,并将其用作模态视图之后的NavController的类。这两个和TabController中的这些都被调用,但这些使它工作。 deanWombourne,不确定这会工作,因为向VC添加方法不起作用。 – Darren

+0

@deanWombourne继承UIViewController不起作用。子类化UINavigationController虽然。我同意,但这是一个危险的分类,一个子类是要走的路。 – Dex

相关问题