4

私はXcode 4.5.1を使用しており、この条件を使用しています

#define IOS_OLDER_THAN_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 )
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )


#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    [image_signature setImage:[self resizeImage:image_signature.image]];
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
#endif
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    [image_signature setImage:[self resizeImage:image_signature.image]];
    return UIInterfaceOrientationMaskLandscapeLeft;
}
#endif

info.plist にキーを追加しました。 ここに画像の説明を入力

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
    </array>

サポートインターフェースの向きを設定します

info.plistにキーを追加し、サポートの向きを設定し、以下のコードを使用しない場合、アプリケーションはios 5.0で動作しません

このコードは機能しますが、小さな代替コンセプトを使用したい..助けてください..

前もって感謝します!!

4

4 に答える 4

3

あなたのアプローチは健康的ではありません。プリプロセッサブロックは、#ifdefステートメントがtrueの場合にのみコンパイルされます。これまでに行ったことは、プリプロセッサステートメントをランタイムパラメータに依存させることです。

すべてのプリプロセッサブロックを削除してみてください。デプロイメントターゲットを5.0にします。

編集:参考までに、これらのメソッドはコールバックメソッドであるため、必要に応じてシステムから呼び出されます。iOS5はshouldAutorotateToInterfaceOrientationメソッドを呼び出し、同様にiOS6はsupportedInterfaceOrientationsとiOS6の回転メソッドを呼び出します。したがって、意図的に2つの異なるシステム用に2つの異なるバージョンのアプリをコンパイルする場合を除き、コンパイル時ではなく、実行時にすべてのシステムの違いを処理する必要があります。

于 2012-10-17T12:20:20.337 に答える
1

ありがとうございます。basar...私は私の問題を解決します...私は私の問題を解決する方法を説明します....

アプリで向きを設定した場合 iOS 5 および IOs 6

その後、手順に従ってください

1) プロジェクトに移動 -> サポート インターフェイスの向きを選択

例:-Landscape LeftとLandscape Rightを選択したい..画像を参照 ここに画像の説明を入力

2) Orientations を選択すると、自動的にキーが info.plist に追加されます ( info.plist で確認します)。追加しない場合は、キーを info.plist に追加します。

例:-

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
    </array>

3)各ビューコントローラーにコードを追加します

// IOS 5 の場合

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
        [image_signature setImage:[self resizeImage:image_signature.image]];
        return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }

// IOS 6 の場合

-(BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    [image_signature setImage:[self resizeImage:image_signature.image]];
    return UIInterfaceOrientationMaskLandscapeLeft;
}

ノート:-

1)条件(IOSバージョン)は必要ありません...両方shouldAutorotateToInterfaceOrientation (IOs 5supportedInterfaceOrientations (IOS 6)がデリゲートであり、ランタイムを呼び出すため... (basarの回答を参照)。

2) IOS 6 のみを使用している場合は、コードは必要ありません。step1 と step2 でのみ動作します

于 2012-10-19T07:26:47.177 に答える
0

別の方法があります-許可された方向を設定せずに:

このソリューションを試してください-iOS5とiOS6で動作します。

UINavigationController ForceRotate

次に、shouldRotate ..デリゲートメソッドを実装して、横向きの間でのみ回転できるようにします。

幸運を!

于 2012-10-17T12:19:13.003 に答える
-2

これらのプリプロセッサ ブロックを削除し、ios5 と ios6 の両方で自動回転をサポートするためにこれを追加します。

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

そして、私たちは電話する必要があります

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;

}

-(BOOL)shouldAutoRotate{
    return YES;
  }

iOS5用

  (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
        {
            return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation ==
        UIInterfaceOrientationPortraitUpsideDown)); }
于 2013-08-22T07:34:10.907 に答える