2

私は、縦向きと縦向きの両方をサポートする iPhone アプリケーションに取り組んでいます。

以前の XCode4.5.1 では、次の方法でこの問題を解決しました。

  • AppDelegate での rootViewController の設定
  • 次のように shouldAutorotateToInterfaceOrientation に言及します。

    -(BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)toInterfaceOrientation {
    
         return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);   }  
    
  • info.plist ファイルで supportedInterfaceOrientation について言及する

現在、新しいXCodeでも同じことを行っていますが、iPhoneシミュレーターv6.0では回転が適切にサポートされていません。

私もこれらの方法で試しました:

-(BOOL) shouldAutorotate {

  BOOL returnValue = NO;

  int interface =  [self preferredInterfaceOrientationForPresentation];

  if(UIInterfaceOrientationIsPortrait(interface)) {

    // Code to handle portrait orientation
    returnValue = YES;
  }
  else {

    // Code to handle Landscape orientation
    returnValue = NO;
  }

  return returnValue;
}

- (NSUInteger) supportedInterfaceOrientations {

  return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return (UIInterfaceOrientationPortrait |
          UIInterfaceOrientationPortraitUpsideDown);
}

iOS > 4.3 のすべてのバージョンで両方の縦向きをサポートする方法を教えてください。

前もって感謝します、 ムルナル

4

2 に答える 2

1

iOS 6で向きが横向きに変わったのになぜ機能しなくなったのですか?

IOS 6.0以降、いくつかの向きの変更により、アプリがPortraitから回転しなくなりました。setRootViewController私にとっての修正、およびここで適用可能な修正は、AppDelegateのウィンドウにいる必要があるということです。以前の回答は、すべて正しいいくつかの提案を提供していますが、私に関連した1つの項目を見逃しています。

application didFinishLaunchingWithOptions、後:

[window makeKeyAndvisible]

また

[window addSubview: viewController.view];

次のように置き換える必要があります。

if([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
    [window setRootViewController:viewController];
} else {
    [window addSubview: viewController.view];
    (or [window makeKeyAndvisible])
}

shouldAutoRotateまた、減価償却の代わりに新しいものを追加する必要がありますshouldAutorotateToInterfaceOrientationが、これは見つけやすく、私にとってはそれほど重要ではありません。

すべての方向が.plistファイルで指定されていることを確認するのと同じです。

デフォルトの向き(すべてiPadの場合、iPhoneの場合は逆さまを除くすべて)supportedInterfaceOrientationsに満足しているため、オーバーライドする必要はありませんでした。UIInterfaceOrientationMaskAllUIInterfaceOrientationMaskAllButUpsideDown

于 2013-01-05T18:58:58.507 に答える
0

私は、iOS 6が登場したとき、何かが機能するようになるまでこれをいじって、それから停止したことを認めなければなりません。しかし、ここに私の推測があります:

これは、アプリが自動回転をサポートしているかどうかを動的にshouldAutorotate変更したい場合に使用することを目的としています。(元の方法のように)サポートしている方向をiOS伝えることは意図されていないと思います。したがって、アプリが自動回転をサポートしている場合、次のようにする必要があると思います。shouldAutorotateToInterfaceOrientation:

-(BOOL) shouldAutorotate {
   return YES;
}

supportedInterfaceOrientationsサポートする方向特定する場所です。

ただし、その方法では、これまで使用していた方法とは異なる方法で実行します(問題がある場合とない場合があります)。この方法ではマスク定数を使用する必要があると思います。したがって、これの代わりに:

- (NSUInteger) supportedInterfaceOrientations {

   return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
}

これを使って:

- (NSUInteger) supportedInterfaceOrientations {

   return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

preferredInterfaceOrientationForPresentationまた、このメソッドが複数の方向を返すことは想定されて いないと思います。優先されるのは、おそらく次のようなものだけです。

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationPortrait;
}

これが関連するAppleのドキュメントです

アップデート:

あなたが試みるかもしれない他のことはこの方法を使うことです:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

AppDelegateクラスで。plistこの方法はオプションですが、すべてのView Controllerまたはアプリのファイルで指定しない場合に備えて、アプリがサポートする方向のデフォルト値を設定できます。plistファイルや他のViewControllerを表示しないため、これが役立つかどうかはわかりません。しかし、それは試してみる何かかもしれません。

于 2012-11-04T09:22:51.083 に答える