有没有办法以编程方式对 LaunchScreen 进行编码
Is there any way to code the LaunchScreen programmatically
我将 Xcode7 和 Swift 与故事板一起使用。当我打开 LaunchScreen.storyboard 并尝试在其上设置自定义 Class 时,Xcode 抱怨无法在 LaunchScreen 故事板上设置自定义 class。
所以我的问题是,有没有什么方法可以对 LaunchScreen 进行编程编码,因为我想避免使用 IB 在其上拖放元素。
不,启动屏幕显示在您的应用程序开始执行之前,以便在应用程序加载时提供从 Springboard 到您的应用程序的转换。
您可以使用固定图像,也可以使用仅使用标准静态 UI 元素(标签和图像)的简单故事板场景。
这个情节提要场景实际上是由 OS 加载和显示的,因此允许您的代码在该上下文中执行会存在安全风险。
运行成功
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
imageArr = ["1.jpeg","2.jpeg","3.jpeg","4.jpeg"]
let RandomNumber = Int(arc4random_uniform(UInt32(self.imageArr.count)))
//imageArr is array of images
let image = UIImage.init(named: "\(imageArr[RandomNumber])")
let imageView = UIImageView.init(image: image)
imageView.frame = UIScreen.main.bounds
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = UIStoryboard(name: "LaunchScreen", bundle: nil).instantiateInitialViewController()
window?.rootViewController?.view.addSubview(imageView)
window?.rootViewController?.view.bringSubview(toFront: imageView)
window?.makeKeyAndVisible()
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
}
return true
}
这实际上不算作编程,因为它只是在编辑 info.plist 文件,但根据我的研究,我发现引入了一种新方法特别是现在使用 SwiftUI 以及它将如何取代我发现的 StoryBoards here
我想我在这里分享它是为了搜索这个主题并第一次遇到这个 post 的人,他们只是想要一种不同于使用 StoryBoards 来创建他们的启动屏幕的方式(比如我)。
我将 Xcode7 和 Swift 与故事板一起使用。当我打开 LaunchScreen.storyboard 并尝试在其上设置自定义 Class 时,Xcode 抱怨无法在 LaunchScreen 故事板上设置自定义 class。 所以我的问题是,有没有什么方法可以对 LaunchScreen 进行编程编码,因为我想避免使用 IB 在其上拖放元素。
不,启动屏幕显示在您的应用程序开始执行之前,以便在应用程序加载时提供从 Springboard 到您的应用程序的转换。
您可以使用固定图像,也可以使用仅使用标准静态 UI 元素(标签和图像)的简单故事板场景。
这个情节提要场景实际上是由 OS 加载和显示的,因此允许您的代码在该上下文中执行会存在安全风险。
运行成功
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
imageArr = ["1.jpeg","2.jpeg","3.jpeg","4.jpeg"]
let RandomNumber = Int(arc4random_uniform(UInt32(self.imageArr.count)))
//imageArr is array of images
let image = UIImage.init(named: "\(imageArr[RandomNumber])")
let imageView = UIImageView.init(image: image)
imageView.frame = UIScreen.main.bounds
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = UIStoryboard(name: "LaunchScreen", bundle: nil).instantiateInitialViewController()
window?.rootViewController?.view.addSubview(imageView)
window?.rootViewController?.view.bringSubview(toFront: imageView)
window?.makeKeyAndVisible()
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
}
return true
}
这实际上不算作编程,因为它只是在编辑 info.plist 文件,但根据我的研究,我发现引入了一种新方法特别是现在使用 SwiftUI 以及它将如何取代我发现的 StoryBoards here
我想我在这里分享它是为了搜索这个主题并第一次遇到这个 post 的人,他们只是想要一种不同于使用 StoryBoards 来创建他们的启动屏幕的方式(比如我)。