【问题标题】:Separate StoryBoards for iPhone 5 and iPhone 4S [duplicate]iPhone 5 和 iPhone 4S 的独立 StoryBoards [重复]
【发布时间】:2012-09-26 04:48:24
【问题描述】:

可能重复:
How to develop or migrate apps for iPhone 5 screen resolution?

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

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

【问题讨论】:

  • 稍微搜索一下就会发现很多信息。试试stackoverflow.com/a/12397309/300292
  • 实际上,我已经看到了那些解决方案,信箱模式或使用基于屏幕大小的代码重新设计。但我想为 1136 和 960 高度的屏幕设计一个单独的 StoryBoard。我们可以使用 pList 为 iPad 和 iPhone 提供单独的故事板。但我想知道,是否可以为 iPhone 5 和 iPhone 4S 加载不同的故事板...... ???
  • 当下一代 iPhone 是 1280x1024 时会发生什么?还是出现了类似大小的迷你 iPad?我的观点是,您需要摆脱为每种外形尺寸进行设计的习惯,并开始使用新的布局约束工具。想象一下,如果您必须针对每种可能的屏幕分辨率重新设计 PC 应用程序......
  • rsswtmr 你的论点是对的......但我正在为 iOS 5.1 开发作为我的部署目标......所以我不能使用 iOS 6 SDK 的布局约束工具......我知道单独的故事板方法不是最好的方法,但仍想知道是否可能??

标签: ios storyboard iphone-5


【解决方案1】:

在您的应用委托中,您需要在- (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 文件的名称

更新(故事板特定答案):

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

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

【讨论】:

  • 它没有回答我的问题....同一个应用程序如何为 iPhone 5 和 iPhone 4S/4/3G 加载单独的故事板??
  • @iSaalis 请查看我更新的答案。
  • 不应该设置 iphone 4(s) screensize.height == 968 吗?
  • @Chris 不,不应该。
  • @Chris 实际屏幕高度为 960 像素,但[[UIScreen mainScreen] bounds].size.height 在 iPhone 4S 中返回 480,比例因子为 2。
猜你喜欢
  • 1970-01-01
  • 2012-09-24
  • 1970-01-01
  • 2013-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-11
  • 2013-05-02
相关资源
最近更新 更多