简体   繁体   English

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

[英]Using different storyboards for different screen sizes? universal xcode app

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. 2.10 - iPhone应用程序还必须在iPad上运行,无需修改,iPhone分辨率和2X iPhone 3GS分辨率。 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. 我们注意到,在运行iOS 9.1的iPad上进行审核时,您的应用无法以iPhone分辨率运行,这违反了App Store审核指南。 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. 具体来说,当我们点击在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. 我已经使用信息plist和常规设置等复制了ipad的第二个故事板。我还需要为不同的iphone设备制作不同的故事板,你可以从图像中看到我的设计是不可能的自动约束。

如果你看看它的年龄,它只能在最后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? 我的问题是:我对旧的View控制器的IB是否与故事板1上的方式相同,并且每个VC上都有重复的代码,或者我是否必须为新的故事板(包括应用程序委托)创建所有新的VC? 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? 其次,我必须在我的app委托中编写代码,以根据屏幕大小或剂量说明使用哪个故事板xcode 7在info plist中执行此操作? All I can seem to find is objc code I only know swift. 所有我似乎都能找到的是objc代码我只知道很快。

so question obj c xcode 5 所以问题对象xcode 5

link ipad and main storyboard 链接ipad和主要故事板

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. 它的工作方式与我针对不同的iphone尺寸相同。 Hope this helps someone else. 希望这有助于其他人。

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 Apple文档

Tutorial 教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM