2

カメラアプリと同じことをしたい: ポートレートモードのみがサポートされているように見えますが、回転すると特定のビューが回転し、ツールバーといくつかのコントロールが同じ場所にあります。

PLIST ファイルでサポートされている向きをすべて無効にしようとしましたが、これは shouldRotate などのデリゲート メソッドを呼び出しません。

サポートされている向きが PLIST にある場合、shouldRotate メソッドに対して NO を返しても、iPhone はすべてのビューを回転させます。

そんなジレンマをどう解決するか?

4

1 に答える 1

2

info.plist、サポートされている唯一の方向を に設定しPortraitます。次に、viewDidLoadメソッドに次を追加します。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];

これにより、メソッドが呼び出されます。

- (void)didRotate:(NSNotification *)aNotification; {
  UIDeviceOrientation currentDeviceOrientation = [[UIDevice currentDevice] orientation];

  switch(currentDeviceOrientation){
    case UIDeviceOrientationPortrait:
      break;
    case UIDeviceOrientationPortraitUpsideDown:
      break;
    case UIDeviceOrientationLandscapeLeft:
      break;
    case UIDeviceOrientationLandscapeRight:
      break;
    default:
      break;
  }
}

そこから、任意のオプションに基づいて、好きなことを行うことができます。また、これを追加することを忘れないでください:

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];

あなたにメソッドを解放します。それが役立つことを願っています!

于 2013-07-20T18:41:55.473 に答える