2012-10-12 60 views
0

我在UITabbarcontroller中有一個UINavigationController。我想在UINavigationController中只旋轉一個視圖cotnroller。iOS 6.0中的設備方向UINavigationController

這是我正在使用的代碼片段。

-(NSUInteger)supportedInterfaceOrientations 
{ 
if (CURRENTDEVICE == IPHONE) 
    return [self.navigationController supportedInterfaceOrientations] | UIInterfaceOrientationMaskAllButUpsideDown; 
else 
    return UIInterfaceOrientationMaskAll; 
} 

-(BOOL)shouldAutorotate { 
return YES; 
} 

我有UINavigationController的一個類別,以及:

#import "UINavigationController+autorotate.h" 

@implementation UINavigationController (autorotate) 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAllButUpsideDown; 
} 

@end 

我不知道如何實現它。

回答

0

你可以用cgrect對它進行硬編碼。這裏是另一個可能幫助你的問題的鏈接。有一個很好的例子,硬編碼兩個不同的旋轉視圖在那裏,但我不推薦它個人。無論如何,我認爲這可能會指向你正確的方向。

https://stackoverflow.com/questions/12867792/ios-rotation-causing-views-to-displace-shift-forcing-me-to-use-non-sensical-har

有一組在這個問題的代碼,可能讓你開始的。你也可以在右舷選擇一個選項(如果你使用的是故事板)來設置IB中的旋轉要容易得多。

希望這有助於

阿德里安

0

supportedInterfaceOrientations實現您的類別,你可以檢查的topViewController。您可以使用kindOfClass:方法確定它是哪個類...然後從默認的導航返回不同的方向。

您也可以子類UINavigationController,並以相同的方式檢查。不建議對導航控制器進行子類化,直到iOS 6時,文檔仍然指出這一點,但Apple工程師告訴我,通過新的旋轉邏輯,您可以繼承UINavigationController的子類。