iPhoneアプリ開発メモ:画面の向きを固定する。 [iPhone SDK]
どんな本にも書いてあるけど、iPhoneアプリの画面の向きを横長にするか、縦長にするか、はたまたゲーム中にプレイヤー交代とばかりに、向きを変えてしまうなどを行う必要がある場合、命令文で向きを指定する方法が必要です。
新規プロジェクトを用意した時に、以下のコードが見つかります。これを改造します。
ホームボタン(丸いボタン)が右に来てほしいなら以下の通りになります。
つまり、横長の右なら
UIInterfaceOrientationLandscapeRight
横長の左なら
UIInterfaceOrientationLandscapeLeft
縦長で下、つまり通常の画面なら
UIInterfaceOrientationPortrait
縦長で上なら
UIInterfaceOrientationPortraitUpsideDown
とすることで、画面の向きを固定する事ができます。
新規プロジェクトを用意した時に、以下のコードが見つかります。これを改造します。
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
ホームボタン(丸いボタン)が右に来てほしいなら以下の通りになります。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
つまり、横長の右なら
UIInterfaceOrientationLandscapeRight
横長の左なら
UIInterfaceOrientationLandscapeLeft
縦長で下、つまり通常の画面なら
UIInterfaceOrientationPortrait
縦長で上なら
UIInterfaceOrientationPortraitUpsideDown
とすることで、画面の向きを固定する事ができます。
コメント 0