2012-09-24 14 views

回答

3

在您的應用程序plist文件中啓用所有旋轉。這將使所有視圖旋轉,而不管視圖控制器中的設置如何。

然後子類根的UINavigationController如下,添加了對iOS5的旋轉控制碼和6根據您的要求:

我正在更新的舊的應用程序用的MainWindow.xib,所以改變了類導航控制器的在xib文件中添加到CustomNavigationController。但是,在一個更現代的應用程序有說主菜單,你會實例化導航控制器是這樣的:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
// Override point for customization after application launch. 

MainMenuVC *masterViewController = [[MainMenuVC alloc] initWithNibName:@"MainMenuVC" bundle:nil]; 
self.navigationController = [[CustomNavigationController alloc] initWithRootViewController:masterViewController]; 
self.window.rootViewController = self.navigationController; 
[self.window makeKeyAndVisible]; 

子類的UINavigationController

#import <UIKit/UIKit.h> 

@interface CustomNavigationController : UINavigationController 

@end 

#import "CustomNavigationController.h" 

@interface CustomNavigationController() 

@end 

@implementation CustomNavigationController 

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

-(BOOL)shouldAutorotate 
{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

@end 

然後子類QLPreview控制器,以便您可以覆蓋輪換代碼這將只啓用QLPreviewController的旋轉。從CustomNavContoller推送的視圖的其餘部分不會隨着CustomNavigationController被鎖定而旋轉。

我在視圖控制器的頂部添加了這個接口和實現,我想呈現QLPreviewController。

@interface RotatingQLPreviewController : QLPreviewController 

@end 

@implementation RotatingQLPreviewController 

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

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAllButUpsideDown; 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

@end 

然後使用你的子類呈現你的QLPreviewController。

RotatingQLPreviewController *preview = [[RotatingQLPreviewController alloc] init]; 
     preview.dataSource = self; 
     [self presentViewController:preview 
          animated:YES 
         completion:^(){ 
          // do more stuff here 
         }]; 

此方法應該適用於其他模態視圖,您要旋轉,但我沒有嘗試過。

我在我的工作,並在這兩個工程的iOS5和6

希望它可以幫助最新的應用程序實現了這個方法。