【问题标题】:iOS iPhone 5 Choose Correct StoryboardiOS iPhone 5 选择正确的故事板
【发布时间】:2012-12-25 08:42:45
【问题描述】:

我正在尝试在我的 iOS 项目中使用这两个故事板,但我无法获取代码以切换到相应的故事板。相反,代码完全没有做任何事情。是我没有正确设置控制开关的设置吗?非 iPhone 5 设备的主故事板称为 MainStoryboard。 iphone 5 合适的布局称为iphone5。我认为这可能是项目配置设置问题。 (这在我的 appdelegate.m 文件中)。

-(void)initializeStoryBoardBasedOnScreenSize {

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
    {    // The iOS device = iPhone or iPod Touch


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

        if (iOSDeviceScreenSize.height == 480)
        {   // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)

            // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
            UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" 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 (diagonally measured)

            // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
            UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"iphone5" bundle:nil];

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

    } else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)

    {   // The iOS device = iPad

        UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
        UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
        splitViewController.delegate = (id)navigationController.topViewController;

    }
}

【问题讨论】:

  • 我可以看到 iPhone 和 iPad 使用了 2 个不同的故事板,但是当您查看故事板时,有一个不错的按钮可以让您在 iPhone 5 屏幕尺寸和之前的屏幕尺寸之间切换,这样您就不用不必创建 2 个全新的故事板。您需要单独的故事板是否有特定原因?
  • 不,您的解决方案正是我想要的。这个按钮在哪里?

标签: iphone ios objective-c cocoa-touch storyboard


【解决方案1】:

我建议只使用 1 个故事板来处理 iPhone 5 与 iPhone 3-4S 的屏幕尺寸。

当您的故事板打开时,底部有一个按钮,可以在两种尺寸之间切换 - 您可以实时查看事物的外观。

该按钮位于右下角 Zoom in % Zoom out 按钮的左侧,如下所示:

要处理对象的框架和位置如何受到屏幕尺寸变化的影响——您需要为视图中的每个对象设置自动调整大小的属性。您可以通过选择一个对象来执行此操作,然后在右侧的 Inspector 面板中,选择 Size 检查器,如下所示:

您看到自动调整大小框中的那些红线了吗?与他们一起玩,看看他们将如何影响您的对象。内层与尺寸相关(如果宽度或高度拉伸),外层与位置相关。

我不确定您的应用程序布局,但根据经验,您可能不得不弄乱内部垂直线(高度将如何变化)和底线(您希望它保持在底部附近)。

你越是搞乱每个,你就会越了解每个人的作用。

【讨论】:

  • 这很有帮助,但我怎样才能专门为某个视图调整对象的大小,而这些对象不会随其他视图配置而改变?
  • 如果您没有看到上面显示的带有红线的 Autosizing 框,请告诉我,您必须关闭自动布局。
  • 我关闭了自动布局,但我的导航栏转到屏幕底部。关于如何解决这个问题的任何想法?
  • 你是把它拖进去还是通过编辑器->嵌入->导航控制器将你的 UIViewController 嵌入到 UINavigationController 中?如果它是嵌入的,则永远不应该从顶部移动——如果你把它拖上去,点击它并确保唯一选择的 Autosizing bar 是 Top 和 width 。
猜你喜欢
  • 2013-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-17
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
  • 2012-03-08
相关资源
最近更新 更多