2012-10-08 41 views
6

自iOS6我有旋轉的大問題。我實現了所有新的旋轉方法(shouldAutorotate,preferredInterfaceOrientationForPresentation,supportedInterfaceOrientation),但所有視圖仍在旋轉。有趣的是 ,意見是保持他們的大小和其餘窗口(在景觀)是黑色的。ios 6應用程序正在旋轉,即使與shouldAutorotate:沒有

這就是我實施它的方式,有什麼不對嗎?

#pragma mark - 
#pragma mark - InterfaceOrientation iOS 5 
//Deprecated in iOS 6 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

#pragma mark - 
#pragma mark - InterfaceOrientation iOS 6 

- (BOOL)shouldAutorotate{ 
    return NO; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 
    return UIInterfaceOrientationPortrait; 
} 

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskPortraitUpsideDown; 
} 

感謝您的幫助。

+0

最後一個不應該是'UIInterfaceOrientationMaskPortrait'嗎? –

+0

它可以,如果它旋轉到兩個縱向方向,但它不應該旋轉到橫向方向 – Fry

+2

只需嘗試更改應用程序的默認方向支持,即在plist文件中的'支持的接口方向'鍵下方,只選擇兩個支持的接口。這將解決你的問題:) –

回答

9

我通過製造類爲navigationcontroller解決了這個問題:

@implementation UINavigationController (iOS6fix) 

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

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

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

@end 

感謝大家的答案!

+0

我不得不創建一個UINavigationController的子類,並使用object_setClass(..,..)將我的navigationController設置爲該類。我也實施了這3種方法。最好將你的答案標記爲公認的答案,這樣人們可以看到因爲這個變化而出現很多混亂和問題 – pnizzle

+0

完美,謝謝! – Fogmeister

+0

工作就像一個魅力 - 非常感謝你.. – geekyaleks

-1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    //Make sure your window to assgin the view controller object to rootViewController, Please don't add controller view as a sub view on window. 
    self.window.rootViewController = viewController; 
} 
0

我有過,其旋轉就算我是地調爲NO。

兩個選項:

  1. 去你的項目設置和更改的可能方向

  2. 刪除所有的自動旋轉的方法。即使它們設置爲NO,它們也會爲我旋轉。

0

我在UIViewController上使用了以下類別,只在iOS5和6上有風景。也許它有助於某人。

#import <UIKit/UIKit.h> 

@implementation UIViewController (iOS6fix) 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeLeft; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 

@end 
相關問題