SSブログ

iPhoneアプリ開発メモ:画面の向きを固定する。 [iPhone SDK]

どんな本にも書いてあるけど、iPhoneアプリの画面の向きを横長にするか、縦長にするか、はたまたゲーム中にプレイヤー交代とばかりに、向きを変えてしまうなどを行う必要がある場合、命令文で向きを指定する方法が必要です。
新規プロジェクトを用意した時に、以下のコードが見つかります。これを改造します。
// 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
とすることで、画面の向きを固定する事ができます。


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:携帯コンテンツ

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。