我創建了一個簡單的應用程序,它有一個紅色背景和一個按鈕(用於理解此問題)。該應用程序處於橫向模式並正在使用iOS6框架構建。ios 6.0 - 景觀不工作 - 子類UINavigationController從不調用shouldAutorotate方法
我已經設置了支持的接口方向的plist屬性只有:風景(右home鍵)
如果我把方法 - (BOOL)shouldAutorotate和 - (NSUInteger)supportedInterfaceOrientations在視圖控制器,並啓動它作爲窗口rootViewController WITHOUT使用UINavigationController,然後橫向方向實現。但是,如果我使用如下例所示的子類UINavigationController並實現 - (BOOL)shouldAutorotate和 - (NSUInteger)supportedInterfaceOrientations,則不會實現橫向方向,並且 - (BOOL)shouldAutorotate從不會被調用。
我在我的子類的UINavigationController下面的代碼:
//For iOS 5.x and below
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationLandscapeRight);
}
//For iOS 6.0
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
-(BOOL)shouldAutorotate
{
return YES;
}
在我的appDelegate我有以下方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
viewController = [[MDViewController alloc] init]; //a very simple viewcontroller containing button on red background which should be in landscape mode
navigationController = [[MDNavigationController alloc] initWithRootViewController:viewController];
[self.window setRootViewController:navigationController.topViewController];
[self.window makeKeyAndVisible];
return YES;
}
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow: (UIWindow *)window {
return UIInterfaceOrientationMaskLandscapeRight;
}
我見過無數的答案,我執行,但發現了類似的問題,這他們失敗了。 謝謝。
是的。這正是我應該做的。謝謝 :) – Zigglzworth