我为每个iOS设备系列创建了一个具有三个不同Storyboard的应用程序。现在,我不知道在应用启动时如何选择正确的Storyboard?我正在检查屏幕高度以识别不同的设备:

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
    // Check Device Family
    var bounds: CGRect = UIScreen.mainScreen().bounds
    var screenHeight: NSNumber = bounds.size.height
    var deviceFamily: String
    if screenHeight == 480 {
        deviceFamily = "iPhoneOriginal"
        // Load Storyboard with name: iPhone4
    } else if screenHeight == 568 {
        deviceFamily = "iPhone5Higher"
        // Load Storyboard with name: iPhone5
    } else {
        deviceFamily = "iPad"
        // Load Storyboard with name: iPad
    }

    return true
}

有人可以在Swift中给我一个可行的解决方案吗?我只找到了ObjC的解决方案。

谢谢。

最佳答案

我想您想打开一个 View ?如果是这样,此代码将完成此工作:

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

它将打开ID为yourViewControllerId的 View Controller

您需要给您的viewcontroller一个标识符。
为此,请突出显示 View Controller ,然后为其指定一个标识符:
然后,将标识符放在StoryBoard ID中。

因此对您而言:
if screenHeight == 480 {
  deviceFamily = "iPhoneOriginal"
  // Load Storyboard with name: iPhone4
  var mainView: UIStoryboard!
  mainView = UIStoryboard(name: "vcLogin", bundle: nil)
  let viewcontroller : UIViewController = mainView.instantiateViewControllerWithIdentifier("iPhone4") as UIViewController
  self.window!.rootViewController = viewcontroller
}

关于ios - 如何通过iOS的Swift调用不同的Storyboard?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24840306/

10-14 23:45