iPhone 5和iPhone 4S分别的StoryBoard

18 浏览
0 Comments

iPhone 5和iPhone 4S分别的StoryBoard

此问题已经在其他地方有答案:

可能重复:

如何开发或迁移iPhone 5屏幕分辨率应用程序?

我该如何为iPhone 5和iPhone 4S / 4 / 3G加载单独的故事板?

我想这样做是因为iPhone 5的屏幕尺寸不同。

admin 更改状态以发布 2023年5月22日
0
0 Comments

在您的应用程序委托中,您需要在 - (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_4inch是为iPhone 5屏幕设计的nib文件的名称

更新(特定于Storyboard的答案):

要在启动时加载不同的故事板,请使用此代码:

    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];
    }

0