为不同的屏幕尺寸使用不同的故事板?通用 xcode 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34048543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:16:30  来源:igfitidea点击:

Using different storyboards for different screen sizes? universal xcode app

iosxcodeipadxcode7ios-universal-app

提问by Grace

I submitted my app for review and got the error

我提交了我的应用程序以供审核并收到错误

2.10 - iPhone Apps must also run on iPad without modification, at iPhone resolution, and at 2X iPhone 3GS resolution. We noticed that your app did not run at iPhone resolution when reviewed on iPad running iOS 9.1, which is a violation of the App Store Review Guidelines. We've attached screenshot(s) for your reference. Specifically, when we tap to login with Facebook on the iPad no action is produced and we are unable to get the app to advance.

2.10 - iPhone 应用程序还必须在 iPad 上以 iPhone 分辨率和 2X iPhone 3GS 分辨率运行,无需修改。我们注意到,在运行 iOS 9.1 的 iPad 上审核时,您的应用没有以 iPhone 分辨率运行,这违反了 App Store 审核指南。我们附上了屏幕截图供您参考。具体来说,当我们在 iPad 上点击使用 Facebook 登录时,不会产生任何动作,我们无法让应用程序前进。

I have copied second storyboard for ipad with the info plist and general settings etc. I also need to make different storyboards for different iphone devices as you can see from the image my design is not possible with auto constraints.

我已经为 ipad 复制了第二个故事板,其中包含信息 plist 和常规设置等。我还需要为不同的 iphone 设备制作不同的故事板,正如您从图像中看到的,我的设计无法使用自动约束。

if you look at the age it is not able to go in the box in the last 3 only the first

如果你看年龄,它不能进入​​最后 3 个盒子,只有第一个

What my question is:do I just IB to the old View controllers the same way I did on storyboard 1 and duplicate code on each VC or do I have to create all new VCs for the new storyboard including app delegate? Secondly do I have to write code in my app delegate to state which storyboard to use depending on screen size or dose xcode 7 do this in info plist? All I can seem to find is objc code I only know swift.

我的问题是:我是否只是像在故事板 1 上所做的那样对旧的视图控制器进行 IB 并在每个 VC 上复制代码,或者我是否必须为新的故事板创建所有新的 VC,包括应用程序委托?其次,我是否必须在我的应用程序委托中编写代码以根据屏幕大小或剂量 xcode 7 在信息 plist 中说明使用哪个故事板?我似乎只能找到我只知道 swift 的 objc 代码。

so question obj c xcode 5

所以问题 obj c xcode 5

link ipad and main storyboard

链接 ipad 和主故事板

回答by Grace

I couldn't use one storyboard for all device sizes due to restrictions in my design so to solve my question I added this code to my app delegate :

由于我的设计限制,我无法为所有设备尺寸使用一个故事板,因此为了解决我的问题,我将此代码添加到我的应用程序委托中:

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    var bounds: CGRect = UIScreen.mainScreen().bounds
    var screenHeight: NSNumber = bounds.size.height
    var deviceFamily: String

    var mainView: UIStoryboard!
    mainView = UIStoryboard(name: "iphone35Storyboard", bundle: nil)
    let viewcontroller : UIViewController = mainView.instantiateViewControllerWithIdentifier("iphone35") as UIViewController
    self.window!.rootViewController = viewcontroller

    if screenHeight == 480  {
        deviceFamily = "iPhoneOriginal"
        // Load Storyboard with name: iPhone4
        var mainView: UIStoryboard!
        mainView = UIStoryboard(name: "Main", bundle: nil)
        let viewcontroller : UIViewController = mainView.instantiateViewControllerWithIdentifier("iphone4") as UIViewController
        self.window!.rootViewController = viewcontroller

    } else {

        var mainView: UIStoryboard!
        mainView = UIStoryboard(name: "IpadStoryboard", bundle: nil)
        let viewcontroller : UIViewController = mainView.instantiateViewControllerWithIdentifier("ipad") as UIViewController
        self.window!.rootViewController = viewcontroller

        if screenHeight == 920 {
            deviceFamily = "Pad"
            // Load Storyboard with name: ipad
            var mainView: UIStoryboard!
            mainView = UIStoryboard(name: "IpadStoryboard", bundle: nil)
            let viewcontroller : UIViewController = mainView.instantiateViewControllerWithIdentifier("ipad") as UIViewController
            self.window!.rootViewController = viewcontroller
        }
    }
}

And then created a new storyboard, copied and pasted the main storyboard onto the second storyboard and adjusted the sizes. And it worked i did the same then for the different iphone sizes. Hope this helps someone else.

然后创建一个新的故事板,将主故事板复制并粘贴到第二个故事板并调整大小。它的工作原理我对不同的 iphone 尺寸做了同样的事情。希望这对其他人有帮助。

回答by ravalboy

You don't need different storyboards, you just need one! All you have to do is work with size classes. You can work on a single storyboard and sets different layout constraint or even have different UI elements for each size class.

你不需要不同的故事板,你只需要一个!您所要做的就是使用尺寸类。您可以处理单个情节提要并设置不同的布局约束,甚至可以为每个尺寸类别设置不同的 UI 元素。

Apple documentation

苹果文档

Tutorial

教程