根据iOS屏幕更改故事板不起作用

时间:2014-10-27 22:41:17

标签: ios objective-c iphone xcode

我不是XCode 6新约束系统的忠实粉丝,所以我决定为每个iPhone尺寸制作自己的故事板,但它并非100%正常工作。它适用于iPhone 4和iPhone 5,但在iPhone 6或iPhone 6+上进行测试时,它会显示iPhone 5故事板。

示例:我使用iPhone 4模拟器运行,我在该故事板上的标签上写着' 4'。

然后我运行了iPhone 5模拟器,我在故事板上的标签上写着' 5'。

然后,我运行iPhone 6和6+模拟器,它显示与iPhone 5故事板相同的标签(它显示错误的故事板)

我想知道你们是否可以指出我的错误,我很感激!

以下是我的故事板:

storyboard screenshoot

这是我的代码(在我的appdelegate.m文件中)

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

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

if (iOSScreenSize.height == 480)
{
    // iPhone 4/4S
    UIStoryboard *iPhone4 = [UIStoryboard storyboardWithName:@"iPhone4" bundle:nil];

    UIViewController *initialViewController = [iPhone4 instantiateInitialViewController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.rootViewController = initialViewController;

    [self.window makeKeyAndVisible];
}

if (iOSScreenSize.height == 568)
{
    // iPhone 5/5S
    UIStoryboard *iPhone5 = [UIStoryboard storyboardWithName:@"iPhone5" bundle:nil];

    UIViewController *initialViewController = [iPhone5 instantiateInitialViewController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.rootViewController = initialViewController;

    [self.window makeKeyAndVisible];
}

if (iOSScreenSize.height == 667)
{
    // iPhone 6
    UIStoryboard *iPhone6 = [UIStoryboard storyboardWithName:@"iPhone6" bundle:nil];

    UIViewController *initialViewController = [iPhone6 instantiateInitialViewController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.rootViewController = initialViewController;

    [self.window makeKeyAndVisible];
}
if (iOSScreenSize.height == 736)
{
    // iPhone 6+
    UIStoryboard *iPhone6Plus = [UIStoryboard storyboardWithName:@"iPhone6+" bundle:nil];

    UIViewController *initialViewController = [iPhone6Plus instantiateInitialViewController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.rootViewController = initialViewController;

    [self.window makeKeyAndVisible];
}

    return YES;
}

0 个答案:

没有答案