iPhone 6 的不同故事板

Different storyboard for iPhone 6

我正在配置我的应用程序以针对不同的 iPhone 使用不同的故事板。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

 if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
if (iOSDeviceScreenSize.height == 480)
{
    // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
    UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_4S" 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];
}
//Not working for iPhone 6 resolution.
if(iOSDeviceScreenSize.height == 667 )
{
UIStoryboard *iphone6Storyboard=[UIStoryboard storyboardWithName:@"Storyboard_Iphone6" bundle:nil];    
UIViewController *initialViewController= [iphone6Storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController  = initialViewController;  
[self.window makeKeyAndVisible];
}
}
return YES;
}

此代码在 iPhone4 模拟器上运行良好,但在 iPhone 6 模拟器上无法运行。一切似乎都很好,但我无法找出问题所在。它没有检测 iPhone 6 的屏幕分辨率。请任何人帮助我。

您的应用可能 运行 处于放大模式,因为您尚未添加对较大手机的支持。如果是这种情况,iPhone 6 的屏幕高度将报告为 568 点,而不是 667。

这是一个解释如何正确添加对较大手机的支持的 SO 答案:

- (NSString *)platformString
{
    NSString *platform = [self platform];

    if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
    if ([platform isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
    if ([platform isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
    if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,3"])    return @"Verizon iPhone 4";
    if ([platform isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([platform isEqualToString:@"iPhone5,1"])    return @"iPhone 5 (GSM)";
    if ([platform isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone5,3"])    return @"iPhone 5c (GSM)";
    if ([platform isEqualToString:@"iPhone5,4"])    return @"iPhone 5c (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone6,1"])    return @"iPhone 5s (GSM)";
    if ([platform isEqualToString:@"iPhone6,2"])    return @"iPhone 5s (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([platform isEqualToString:@"iPhone7,2"])    return @"iPhone 6";

    if ([platform isEqualToString:@"x86_64"])       return @"Simulator";

    return platform;
}

试试这个。此代码将帮助您识别当前 运行 的模拟器或设备。如需完整参考,您可以使用此 git 集线器 link

https://gist.github.com/Jaybles/1323251