6773236388 d2776ace5a b

iOS 6から、アプリをランドスケープモードにするメソッド「shouldAutorotateToInterfaceOrientation」が使えなくなりました。

というわけで、iOS 6でランドスケープモード対応のアプリを開発する場合の対処方法を備忘録として書いて起きます。

self.window.rootViewControllerにviewControllerを代入する。

まずデバッガにrootViewControllerになんか入れてくれと出ているはずなので、appDelegate.mに以下のコードを入れておきます。

self.window.rootViewController = newEntryNavigationCtr;

実際の例としてはこんな感じ。↓↓

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.newEntryViewCtr = [[[NewEntryViewCtr alloc] init] autorelease];
newEntryNavigationCtr = [[UINavigationController alloc] initWithRootViewController:newEntryViewCtr];
[self.window addSubview:newEntryNavigationCtr.view];
self.window.rootViewController = newEntryNavigationCtr;
[self.window makeKeyAndVisible];
return YES;
}

*このアドバイスをくれた @frnk さん誠にありがとうございます!

これだけでも、ランドスケープできましたが「shouldAutorotateToInterfaceOrientation:はdeprecatedだよ! - Debian GNU/Linux 3.1 on PowerMac G4」によると以下のコードも入れて置いたほうがよいみたいです。

- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}

もちろんiOS 6以下のiOSに対応する場合は、shouldAutorotateToInterfaceOrientationのメソッドも引き続き書いておきましょう。

するぷろのコードは結構、shouldAutorotateToInterfaceOrientationを利用していたので修正が大変だったなぁ・・・。(;´∀`)

iOS 6の開発に関する記事は、こんなのも書いています。↓↓

【iOS 6】UITableViewの背景を透明にする方法。指定する場所がbackgroundColorからbackgroundViewに。 | 和洋風KAI