2010年9月13日月曜日

デバイスの回転を検知する。

shouldAutorotateToInterfaceOrientation メソッドで YES を返すようにすると回転時に以下のメソッドが実行されます。いずれも UIViewController クラスのメソッドです。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    return YES;
}

// 回転後に実行される
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)FromInterfaceOrientation {
  if(FromInterfaceOrientation == UIInterfaceOrientationPortrait){
       // 横向き
    }
    else {
       // 縦向き
    }
}
 
・UIInterfaceOrientationPortrait
ポートレートモードで、デバイスを垂直に持った時にホームボタンが下部にある状態です。
・UIInterfaceOrientationPortraitUpsideDown
ポートレートモードですが上下逆で、デバイスを垂直に持った時にホームボタンが上部にある状態です。
・UIInterfaceOrientationLandscapeLeft
ランドスケープモードで、デバイスを垂直に持った時にホームボタンが左側にある状態です。
・UIInterfaceOrientationLandscapeRight
ランドスケープモードで、デバイスを垂直に持った時にホームボタンが右側にある状態です。

ビューの自動回転
http://developer.apple.com/jp/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/AutorotatingViews/chapter_11_section_1.html

0 件のコメント:

コメントを投稿