【问题标题】:Creating specific storyboard to iPhone X为 iPhone X 创建特定的故事板
【发布时间】:2018-05-08 12:55:49
【问题描述】:

我很难在单个故事板上使用自动布局和约束将所有内容扩展到 iPhone X。

iPhone 4s 小屏幕、6、6+ 都运行良好,但带有安全区域的 iPhone X 高屏幕是定制设计应用程序的噩梦。只为 iPhone X 创建特定情节提要更容易,而将其他情节提要用于所有其他屏幕尺寸。

只要有可能做到这一点。 我可以仅将特定情节提要加载到 iPhone X 吗?怎么样?

我已经有一个用于 iPad 的情节提要和另一个用于 iPhone,但这可以在 plist 上进行配置。

谢谢!

【问题讨论】:

标签: ios iphone autolayout storyboard


【解决方案1】:

如果你很了解约束概念,实际上没有必要这样做,但你想加载不同的 xib 文件而不是你可以做到的。

您必须将检查设备的条件设置为 iphoneX 或 不是。您可以根据设备的屏幕尺寸比较设备。所以我不是 写任何提示。

if (iphoneX) {

  // initialized the Instance of ViewController with identifier(OR with NIB name) which is defined for iphoneX.

} else {

  // initialized the Instance of ViewController with identifier(OR with NIB name) which is Not defined for iphoneX.
}

编码愉快!

【讨论】:

  • 好的,但这并不能回答问题。 appDelegate 上的 ondidFinishLaunchingWithOptions 应该放在哪里?如何调用不同的情节提要?
  • @tomDev ,而不是在 didFinishLaunchingWithOptions 中,当您想要推送屏幕或想要初始化它时。是的,但是如果这个类被用作 rootViewController 或 tabBarItem 之一,那么你可以在 didFinishLaunchingWithOptions 中使用它。
  • @tomDev ,回答很简单。
【解决方案2】:

我知道这不是最好的方法,但在我有时间制作通用故事板之前它可以完美运行。

将此添加到 AppDelegate 以在 iPad、iPhone X 和其他 iPhone 之间拆分故事板。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    let storyboard = grabStoryboard()

}


func grabStoryboard() -> UIStoryboard {
    // determine screen size
    let screenHeight = UIScreen.main.bounds.size.height
    let screenWidht = UIScreen.main.bounds.size.width
    var storyboard: UIStoryboard! = nil

    if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone) {

        if ( screenHeight == 812 && screenWidht == 375) {

            print ("iphone x") 
            storyboard = UIStoryboard(name: "Main_iPhoneX", bundle: nil)

        } else {

            print ("all other phones")
            storyboard = UIStoryboard(name: "Main", bundle: nil)

        }

    } else {

        storyboard = UIStoryboard(name: "Main_iPad", bundle: nil)

    }

    return storyboard
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    • 2015-09-20
    • 2013-01-26
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 2012-04-10
    相关资源
    最近更新 更多