0

ビューコントローラをUIDeviceOrientationDidChangeNotificationに登録していますが、デバイスの向きが間違って返されます。ビューコントローラのinit関数に登録しています

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

これは私のデバイスのNotificationReceiverメソッドです。

-(void)handleOrientationChangeNotification:(NSNotification *)notification
{ 
    if(IS_IPHONE)
    {
        UIDeviceOrientation currentDeviceOrientation =  [[UIDevice currentDevice] orientation];
    .
    .
    .
}

デバイスの向きが変わると、いつも間違った向きになります。

4

2 に答える 2

3

このリンクのアップルサイトで解決策を見つけます

UIDeviceOrientationLandscapeRightに割り当てられUIInterfaceOrientationLandscapeLeftUIDeviceOrientationLandscapeLeftに割り当てられUIInterfaceOrientationLandscapeRightます。これは、デバイスを回転させるにはコンテンツを反対方向に回転させる必要があるためです。

于 2012-10-15T09:33:09.000 に答える
2

これはおそらく、Apple が UIViewController の方向を管理する方法を変更したために発生しています。iOSiOS6 shouldAutorotateToInterfaceOrientationコンテナ ( などUINavigationController) は、自動回転する必要があるかどうかを決定するために、子を参照しません。デフォルトでは、アプリとビュー コントローラーでサポートされているインターフェイスの向きはUIInterfaceOrientationMaskAll、iPad イディオムとUIInterfaceOrientationMaskAllButUpsideDowniPhone イディオムに対して に設定されています。

同じことに関する詳細については、このリンクにアクセスしてください 。以下に、方向の変更を処理するためのカテゴリを作成しました。

SO iOS6 で UIViewController の方向を管理するために、さらに 2 つのメソッドを実装する必要があります。

IOS6 で導入 向きの変更を許可

 - (BOOL)shouldAutorotate
  {

    return YES;

  }

デバイスでサポートされる方向の数を返します

 - (NSUInteger)supportedInterfaceOrientations
 {
    return  UIInterfaceOrientationMaskAll;

 }

次に、取得している方向を確認します。

編集: このコードをルート ViewController として追加された FirstViewController に配置します。これは、UIViewController が方向を判断するのに役立ちます。

@implementation UINavigationController (RotationIn_IOS6)

 -(BOOL)shouldAutorotate
  {
   return [[self.viewControllers lastObject] shouldAutorotate];
  }

  -(NSUInteger)supportedInterfaceOrientations
 {
   return [[self.viewControllers lastObject] supportedInterfaceOrientations];
 }

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
 {
   return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
 }

 @end

お役に立てれば幸いです。

于 2012-10-15T07:49:02.500 に答える