忍者ブログ
MASTER →  ADMIN / NEW ENTRY / COMMENT
現代魔法(nearly equal 情報技術)を勉強中な人のメモ(チラシの裏)
/ 2024/03/29 (Fri) / 編集
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

/ 2009/07/03 (Fri) / 編集
まず「shouldAutorotateToInterfaceOrientation:」でYesを返します。
//本体の回転を検出し、Viewを回転させる
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return YES;
}
そうすると、これがYESだと自動的にWindowを回転し、「willRotateToInterfaceOrientation」や「didRotateFromInterfaceOrientation」 が呼ばれるようになります。
//本体の回転に会わせて処理を変える関数
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//本体の方向に応じてViewを変更
 switch (toInterfaceOrientation) {
   case UIInterfaceOrientationPortrait:
    NSLog(@"正位置");//ボタンが下
    [pub showCenterView];//Viewを呼び出す(下記参照)
     break;
   case UIInterfaceOrientationPortraitUpsideDown:
     NSLog(@"上下逆");
     [pub showFlipView];
     break;
   case UIInterfaceOrientationLandscapeLeft:
     NSLog(@"右回転");//NSLog(@"左が上");
     [pub showRightView];
     break;
   case UIInterfaceOrientationLandscapeRight:
     NSLog(@"左回転");//NSLog(@"右が上");
     [pub showLeftView];
     break;
   default:
     NSLog(@"Unkown");
     break;
   }
}
実際にViewを切り替える関数はこんな感じにしてみた
//本体を右に回転させたときに呼ばれる関数
-(void)showRightView{
//nowView : 現在一番上にあるView
//RootView : 親になるView
//rightViewController : 表示させたいViewのコントローラ
  NSLog(@"[Public:showRightView]");
  //現在一番上にあるViewを削除
  [nowView removeFromSuperview];
  //右回転させる
  [[UIApplication sharedApplication]   setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
  //あたらしいViewをRootViewに追加(一番上に表示)
  [rootViewController.view addSubview:rightViewController.view];
  //実行
  [UIView commitAnimations];
  //現在のViewとして登録
  nowView = rightViewController.view;
}
この回転方向を表す長ったらしい引数はUIApplicationクラスのUIInterfaceOrientationコンスタントらしい
  1. UIInterfaceOrientationPortrait
  2. ホームボタンが下になるデフォルトの位置
  3. UIInterfaceOrientationPortraitUpsideDown
  4. 上下逆になる
  5. UIInterfaceOrientationLandscapeRight
  6. 本体を右に90度回転させたとき(ホームボタンが左)
  7. UIInterfaceOrientationLandscapeLeft
  8. 本体を左に90度回転させたとき(ホームボタンが右)

拍手[1回]

PR
忍者ブログ [PR]