4

古いバージョンの Xcode で作成されたアプリがあります。現在、Xcode 4.6.1 を使用しています。これは、社外で開発された別の開発者から継承したアプリです。

このアプリの問題の 1 つは、そのインターフェイスです。デフォルトは LandscapeLeft です (これは pList ファイルで設定された値です)。アプリはこのディレクティブを無視し、代わりに縦向きモードをデフォルトに設定します。

コードにこの値を強制的に適用させるために必要なことはありますか? 私はiOS/Objective-Cに比較的慣れていません。コードはコンパイルされて実行されますが、インターフェースが私が望んでいることをしていないだけです。

これはiPad専用アプリなので、少し簡単です。

編集 問題のあるviewControllerの1つに次のコードを追加しようとしましたが、受け入れられません。このビューを強制的に横向きにする方法について何か考えはありますか? (IDE に設定はありますか? Xcode には向きの属性があったようですが、4.6.1 では見つかりません)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return ((interfaceOrientation==UIInterfaceOrientationMaskLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationMaskLandscapeRight));
}

- (NSUInteger) supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

- (NSInteger) supportedInterfaceOrientationsForWindow
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL) shouldAutoRotate
{
    return YES;
}
4

12 に答える 12

7

これがお役に立てば幸いです。AppDelegate.mクラスにこの(必要な向きの)メソッドの1つを追加します

アプリケーションをランドスケープ モードで強制的に完全に実行するには:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskLandscape;
}

ポートレート モードでアプリケーションを強制的に完全に実行するには:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}
于 2013-05-07T14:19:47.603 に答える
3

アプリのビュー コントローラーがビューの向きを強制するかどうかを確認します。「ビューの回転の処理」セクションと、Apple のドキュメントで回転に関連するタスクを確認してください。

http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html

于 2013-04-18T18:05:16.903 に答える
0

The rootViewController-property was added to the UIWindow-class in iOS 4. 通常、この値はUIApplicationDelegate(あなたの場合はおそらくAppDelegate.m) に設定されます。プロパティが正しくない場合、rootViewController回転イベントがビュー階層を正しく通過しないことがあります。

self.window.rootViewController = myRootViewController;まだそこにない場合は試してください。

于 2013-05-08T12:24:31.193 に答える
0

iOS 6.0以降をお使いですか?次に、preferredInterfaceOrientationForPresentation メソッドも実装してみてください。

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

ルート ビューが UINavigationController の場合、それをサブクラス化し、新しい方向メソッドを実装することができます。

同じナビゲーションコントローラーにプッシュされた異なる UIViewController で異なるデフォルトの向きをサポートしたい場合、次のようなカスタム UINavigationControler があります。

@implementation MyNavigationController

- (BOOL)shouldAutorotate;
{
    return YES;
}

- (NSUInteger) supportedInterfaceOrientations
{
    if ([[self topViewController] respondsToSelector:@selector(supportedInterfaceOrientations)])
        return [[self topViewController] supportedInterfaceOrientations];
    else
        return [super supportedInterfaceOrientations];
}

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
{
    if ([[self topViewController] respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)])
        return [[self topViewController] preferredInterfaceOrientationForPresentation];
    else
        return [super preferredInterfaceOrientationForPresentation];
}

@end
于 2013-05-08T11:42:40.560 に答える
0

Xcode でプロジェクト ファイルをクリックします。次に、「ターゲット」をクリックします。向きを選択してください (下にスクロールしてください)。IB でビュー (インスペクターの下) が縦向きに設定されていることを確認します。

于 2013-04-18T18:06:15.167 に答える
0

そこからjhhlを引用するIPadの横向きでアプリケーションを起動する投稿を確認 してください:

サポートされているインターフェースの向きを最初のスロットに別の向きで設定している場合、info.plist での初期インターフェースの向きの設定は無視されます! 最初の向きもそこに置きます - するとシミュレーターが正しく起動し、アプリも同様に起動します

編集:もう1つ-問題はまったく別の場所にある可能性があります。適切なView Controller階層があると確信していますか? コントローラーがウィンドウまたは別のコントローラーに正しい方法で追加されていない場合、回転イベントとロジックは機能しません。実際、数か月前に書いたアプリをチェックしたところ、同じ問題がありました-iPadは横向きで起動する必要があります。派手なことは何もしませんでしたが、Info.plist で向きを設定し、rootViewController をアタッチし、回転メソッドで適切な戻り値を設定しました。

于 2013-05-08T04:35:13.290 に答える
0

ランドスケープ モードでの起動

iOS 5 では、すべてのビュー コントローラーに次のメソッドを実装する必要があります。

// Called only in IO 5 and earlier.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft );
}

そして、Info.plist で UIInterfaceOrientation "Initial interface orientation" を UIInterfaceOrientationLandscapeRight に設定します。

ビューを横向きモードでレイアウトします。

Appleの開発者向けドキュメントによると

于 2013-05-02T18:30:11.020 に答える
0

iOS 6 より前、つまり iOS 5 以前では、アプリとビュー コントローラーの回転は個々のビュー コントローラーによって制御されていましたが、iOS 6 以降では、回転を担当するビュー コントローラーは UINavigationController や UITabBarController などのコンテナー ビュー コントローラーです。プロジェクトで rootviewcontroller として何を使用していますか??

Autorotation は、この投稿で明確に説明されています- iOS の Autorotation

于 2013-05-06T11:51:30.497 に答える