2012-11-11 42 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

相關問題