1

Xcodeを4.5に更新し、以下のようにオリエンテーションメソッドを実装しました

  -(BOOL)shouldAutorotate{

    return YES;

  }

-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;
}

willRotateToInterfaceOrientationメソッドでボタン、ラベル、画像のフレームサイズを設定しています

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{


  if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait )||
        ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown ))
  {

    // set frame sizes for portait

   }

  else if(( [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft )||
            ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight ))

  {

    // set frame sizes for landscape

   }

}

ただし、シミュレーターを回転させているときにこのメソッドが呼び出されない場合や、別のviewControllerからナビゲートしているときにシミュレーターが方向を検出しない場合があります。info.plistファイルを確認しました-問題ありません。

4

2 に答える 2

4

Apple は、IOS 6.0 で shouldAutorotatetoInterfaceOrientation 呼び出しを呼び出しませんが、それを送信するビュー コントローラーをメイン ウィンドウに指示する必要があります。

window.rootViewController をアプリのトップレベルのビューコントローラーに設定することで、アプリで回転を機能させることができました

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   ...
   window.rootViewController = topLevelViewController;
   ...
}

私のアプリの iPhone バージョンは 2 つの縦向きしかサポートしていないため、トップの iPhone ビュー コントローラーには新しいメソッドが必要でした。

- (NSUInteger)supportedInterfaceOrientations 
{
  return  UIInterfaceOrientationMaskPortrait |  
          UIInterfaceOrientationMaskPortraitUpsideDown;
}

Buzz Touchに関する議論はこちらです。

于 2012-09-24T15:59:06.207 に答える
0

Apple は ios6 からの shouldautorate メソッドを非推奨にしました。代わりにこれらのメソッドを使用してください。

- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0);
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
// Returns interface orientation masks.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation NS_AVAILABLE_IOS(6_0);
于 2012-11-13T13:29:19.053 に答える