有人让 Swift 在 iOS 7 上运行得足够好来处理多个 Storyboard吗?
至少,有人获得了可以正常工作的设备后缀吗?每当我将 Master-Detail 示例项目中的 Main.storyboard 重命名为 Main~iPad 和/或 Main~iPhone 时,我似乎都会遇到加载错误。
我认为这与设备后缀有关,因为以下内容将实现我想要的:
var window: UIWindow?
var storyboard: UIStoryboard?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
//device suffixes ~iPad and ~iPhone don't work right now, in fact, a lot of .storyboard stuff is borked
self.window = UIWindow() //window doesn't have an init with frame class, so we need to set that to the screen bounds in order to have touch
self.window!.frame = UIScreen.mainScreen().bounds
//Since I'm targeting iOS 7 and later, we can't use UISplitViewController everywhere (it becomes universal in iOS 8)
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
self.storyboard = UIStoryboard(name: "Main~iPad", bundle: nil)
self.window!.rootViewController = self.storyboard!.instantiateInitialViewController() as UIViewController
//iPad-specific initialization
let splitViewController = self.window!.rootViewController as UISplitViewController
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.endIndex-1] as UINavigationController
splitViewController.delegate = navigationController.topViewController as DetailViewController
}else{ //iPhone / iPod
self.storyboard = UIStoryboard(name: "Main~iPhone", bundle: nil)
self.window!.rootViewController = self.storyboard!.instantiateInitialViewController() as UINavigationController
//iPhones should just have a navigation controller as their root view
}
self.window!.makeKeyAndVisible() //got to manually key since we're initializing our window by hand
//at this point we have the iPad storyboard or the iPhone storyboard loaded
return true
}
我知道我们似乎将不再使用特定于设备的标签,但回答这个问题对于需要继续支持 iOS 7 的人们来说非常重要。
最佳答案
设备特定的内容和方向很快就会发生变化。无法保证 iOS 7 和 Mavericks 的 Swift 源代码兼容性,但可以保证二进制兼容性。也许您遇到了兼容性的限制。
关于iphone - iOS 7.0 Swift 项目中的多个(特定于设备的) Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24034521/