備忘録のような何か

何か += 備忘録( 日々のこと, 妄想, IT, DIY, 畑仕事 );

iPhoneアプリ開発で画面固定(cocos2d使うときに注意すること)

移転しました。

約5秒後に自動的にリダイレクトします。



iPhoneアプリ開発で画面固定する場合、XcodeからGUIで設定できます。

f:id:m_uta:20130209002846p:plain

実際の設定は
info.plistの"Supported interface orientations"に追加されます。


と、普通ならこれで終わりなんですが、
cocos2dテンプレートを使ってプロジェクトを作成した場合、
初期状態でAppDelegate.mに以下のコードが定義されています。

// Supported orientations: Landscape. Customize it for your own needs
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

画面固定したいのにこれでは元も子もない。
ということで、このメソッドをごっそりと削除してしまうか、
NOを返すようにしてやりましょう!

// Supported orientations: Landscape. Customize it for your own needs
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}

これでOKです。


shouldAutorotateToInterfaceOrientation
デバイスの回転を検知したときに呼ばれるデリゲートメソッド