トップ «前の日記(2012-01-22) 最新 次の日記(2012-01-24)» 編集

Cocoa練習帳

iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど

2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|

2012-01-23 [iOS]iPhoneの向きを変更する

Xcodeで、ターゲットのSummaryのiPhone/iPod Deployment InfoのSupported Device Orienttationsで、対応する向きを選択する。(下記の図の赤い丸で囲まれたボタン)古い資料では、Info.plistのUIInterfaceOrientationキーのカスタマイズが説明されているが、この操作によってInfo.plistが更新される。

画像の説明

四つの項目(Portrait, Upside Down, Landscape Left, Landscape Right)の選択順には意味があって、最初に選択された物が、起動時の画面の向きという事になるようだ。

ユーザーがiPhoneの向きを変更するのに追従して、自動で画面の向きを変更したい場合は、ビュー・コントローラのshouldAutorotateToInterfaceOrientation:メソッドをカスタマイズする。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    BOOL    result = YES;
    if (interfaceOrientation == UIInterfaceOrientationPortrait)
        result = YES;
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        result = YES;
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        result = YES;
    else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        result = NO;
    return result;
}

例えば、上記の例は、上下が逆さま(UIInterfaceOrientationPortraitUpsideDown)以外が自動で向きが変わるというコードだ。

画像の説明 画像の説明

_ 関連情報

User Experience Coding How-To's
iOS Developer Libraryの情報です。
本日のツッコミ(全1件) [ツッコミを入れる]
_ eien (2012-01-31 00:55)

Appleは、 <br>UIInterfaceOrientationIsLandscape <br>UIInterfaceOrientationIsPortrait <br>を使えと推奨していますが、それだとUP/DOWNとLEFT/RIGHTが区別できないのでそれを区別したい状況があるとマクロを使っていいい物かどうか悩みます。


トップ «前の日記(2012-01-22) 最新 次の日記(2012-01-24)» 編集