15

重複の可能性:
iPhone 5 の画面解像度用にアプリを開発または移行するにはどうすればよいですか?

iPhone 5 と iPhone 4S/4/3G に別々のストーリーボードをロードするにはどうすればよいですか??

iPhone 5は画面サイズが違うのでやりたいです。

4

1 に答える 1

32

アプリのデリゲートで、次のコードを追加/置換する必要があります- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_4inch" bundle:nil];
} else {
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}

ViewController_4inchiPhone 5画面用に設計されたnibファイルの名前はどこですか

更新 (ストーリーボード固有の回答):

起動時にさまざまなストーリーボードをロードするには、次のコードを使用します。

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

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

        // Instantiate the initial view controller object from the storyboard
        UIViewController *initialViewController = [iPhone35Storyboard 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  = initialViewController;

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

    if (iOSDeviceScreenSize.height == 568)
    {   // iPhone 5 and iPod Touch 5th generation: 4 inch screen
        // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
        UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4" bundle:nil];

        UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.rootViewController  = initialViewController;
        [self.window makeKeyAndVisible];
    }
于 2012-10-05T06:57:20.923 に答える