2

私は現在、iPhone3GS用のアプリを開発しています。展開目標は5.1に設定されており、セグエやシーンがたくさんあるリッチなストーリーボードを作成しました。昨夜、iPad、iPhone 4、iPhone 5でアプリを利用できるようにしたいと思いました。画面サイズや解像度が異なる場合は、別のストーリーボードを作成することにしました。最近、SOのスプリングとストラットについて読み始めたばかりなので、これがベストプラクティスかどうかはわかりません。そのため、情報はあまりわかりませんが、私のために、別のストーリーボードを立ち上げたかっただけです。アプリケーションの起動が終了したとき。ただし、この望ましい効果は発生していません。

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    // ViewControllerWelcome *viewControllerWelcome = (ViewControllerWelcome *)[[ViewControllerWelcome alloc]init];

//    NSManagedObjectContext *context = (NSManagedObjectContext *) [self managedObjectContext];
//    if (!context) {
//        NSLog(@"\nCould not create *context for self");
//    }

    //[viewControllerWelcome setManagedObjectContext:context];

    // Do I need to declare my view controllers here?

    // Pass the managed object context to the view controller.

    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

    if (iOSDeviceScreenSize.height == 480)
    {
        // Instantiate a new storyboard object using the storyboard file named iPhoneLegacy
        UIStoryboard *iPhoneLegacy = [UIStoryboard storyboardWithName:@"iPhoneLegacy" bundle:nil];

        // Instantiate the initial view controller object from the storyboard
        UIViewController *ViewControllerWelcome = [iPhoneLegacy instantiateInitialViewController];

        // Instantiate a UIWindow object and initialize it with the screen size of the iOS device
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        // Set the initial view controller to be the root view controller of the window object
        self.window.rootViewController = ViewControllerWelcome;

        // set the window object to be the key window and show it
        [self.window makeKeyAndVisible];
    }

    if (iOSDeviceScreenSize.height == 968)
    {
        // Instantiate a new storyboard object using the storyboard file named iPhone4
        UIStoryboard *iPhone4 = [UIStoryboard storyboardWithName:@"iPhone4" bundle:nil];

        UIViewController *ViewControllerWelcome = [iPhone4 instantiateInitialViewController];
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.rootViewController  = ViewControllerWelcome;
        [self.window makeKeyAndVisible];
    }

    // iPhone 5 1136 x 640

    // iPad Legacy 1024 x 768

    return YES;
}

別のストーリーボードファイルがシミュレーターにロードされているかどうかをテストしようとすると、シミュレーターはiPhoneLegacyストーリーボードをロードするだけです。

このコードは物理デバイスでのみ機能しますか?また、シミュレーター用に別のコードが必要ですか?

4

1 に答える 1

4

何よりもまず、余分なストーリーボードを削除してください! iPhone 用に 1 つ、iPad 用に 1 つだけ必要です。

すべての iPhone/iPod Touch サイズに対応する単一のストーリーボードを作成する簡単な方法があります。

  1. iPhone の画面サイズ (iPhone 5 を含む) の絵コンテは 1 つだけにしてください。
  2. すべての画像に対して @2x ファイルを作成します。
  3. 3.5 インチと 4 インチのサイズを切り替えるために、Apple は右下に、内向きまたは外向きの矢印が付いた長方形のようなボタンを提供しています。このボタンは、3.5 インチと 4 インチの画面サイズを切り替えます。

それでおしまい!iPhone/iPod Touch ごとに 1 つのストーリーボードを作成するためのコードは実際には必要ありません。


iPad の場合、iPad 用に作成された新しいストーリーボードを作成する必要があります。また、UI コードを更新して、iPhone と iPad の両方の画面サイズと互換性があることを確認する必要があります。繰り返しますが、iPad 用の @2x 画像サイズも必ず作成してください。

于 2013-01-02T17:41:37.610 に答える