5

私のユニバーサルアプリでは、iPhoneとiPadの異なる向きを処理する必要があります。iPadの場合、横向きを許可する必要があり、iPhoneのポートレートのみを許可する必要があります。私は最初に以下のコードを返しました

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);

    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

IOS 5では正常に動作していますが、IOS6ではautorotateメソッドはまったく実行されません。その後、メソッドをに変更しました。

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}

このメソッドでさえ、IOS6ではまったく実行されません。

私のplist設定は

ここに画像の説明を入力してください

IOS5とIOS6の両方で両方の向き[iPhone-portrait、iPad-landscape]を処理する必要があります。この問題を修正するためにガイドしてください。

4

4 に答える 4

3

ルートビューコントローラーはUINavigationコントローラーですか、それともUITabbarコントローラーですか?その場合、View Controllerでこれらのメソッドを呼び出していると、これらのメソッドは機能しません。

したがって、これらのコンテナビューコントローラでObjective Cカテゴリを作成し、プロジェクトに追加します。

@implementation UINavigationController (autorotate)


 -(NSUInteger)supportedInterfaceOrientations
 {
   //make the check for iphone/ipad here

if(IPHONE)
    {
return UIInterfaceOrientationMaskPortrait;
    } 
else
    {
return UIInterfaceOrientationMaskLandscape;
    }

 }

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
 {
return UIInterfaceOrientationPortrait;
 }

 - (BOOL)shouldAutorotate
 {
return NO;
 }
于 2013-01-04T06:48:33.667 に答える
2

このメソッドをアプリデリゲートに追加すると、100%機能します

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window  // iOS 6 autorotation fix
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationPortraitUpsideDown;
    }
    else
        return  UIInterfaceOrientationMaskAll;
}
于 2013-06-19T07:30:05.073 に答える
0

必要なのは次のとおりです。

#pragma mark - iOS 5.1 and under Rotation Methods

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; {
  if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
  }
  else{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
  }
}

#pragma mark - iOS 6.0 and up Rotation Methods

- (BOOL)shouldAutorotate; {
  return YES;
}

- (NSUInteger)supportedInterfaceOrientations; {
  if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
  }
  else{
    return UIInterfaceOrientationMaskLandscape;
  }
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation; {
  if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
    return UIInterfaceOrientationPortrait;
  }
  else{
    return UIInterfaceOrientationLandscapeLeft;
  }
}

確認しなければならないのは2倍です。

まず、これがあなたに実装されていることRootViewController。を(または)UIViewController内に埋め込む場合は、これらのメソッドを実装するカスタム(またはカスタム)クラスを作成して使用する必要があります。UINavigationControllerUITabBarControllerUINavigationControllerUITabBarController

次に、ファイルでサポートされている方向があることを確認する必要がありInfo.plistます。それ以外の場合、システムはこれらのメソッドの戻り値を上書きします(注:ターゲットの[概要]ページのボタンをクリックすることで、これらの値を簡単に変更できます)。

お役に立てば幸いです。

于 2013-01-04T06:42:11.577 に答える
0

これがPradeepの答えの迅速なバージョンです。作業したいものを取得するために、すべてのナビゲーションコントローラーをサブクラス化する必要はありません(つまり、iPhoneの場合のみ横向きをオフにします)

これをアプリデリゲートに追加するだけです。

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    } else {
        return Int(UIInterfaceOrientationMask.All.rawValue)
    }
}
于 2015-03-02T21:42:26.943 に答える