1

向きが縦から横に、またはその逆にいつ切り替わるかを知る必要があります。聞くことを選択した場合UIDeviceOrientationDidChangeNotification、表向き、裏向きなどになりますが、インターフェイスが回転している場合にのみコードを実行する必要があります。

私はhttp://the.ichibod.com/kiji/how-to-handle-device-rotation-for-uiviews-in-ios/として行うことができます

- (void)deviceOrientationDidChange:(NSNotification *)notification {

 //Obtaining the current device orientation
  UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

 //Ignoring specific orientations
  if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown     || orientation == UIDeviceOrientationUnknown || currentOrientation == orientation) {
   return;
  }

  [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(relayoutLayers) object:nil];
  //Responding only to changes in landscape or portrait
  currentOrientation = orientation;
}

最善のアプローチは何ですか?

4

1 に答える 1

2

デバイスの向きを使用するときに、ビューの向きについて同様の問題が発生しました。上、下、左、右がありますが、不明であり、それが何を意味するのかまだわかりません(列挙型のint 5、0は不明です)。とにかく、私が頼りにしたのは、ステータスバーの向きを検出することでした。それは、ユーザーが見ているものに対してより一貫性を保ちます。

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

お役に立てれば。

于 2012-11-01T15:34:05.727 に答える