我正在使用带有故事板的Xcode7和Swift。当我打开LaunchScreen.storyboard并试图在其上设置一个自定义类时,Xcode抱怨说在LaunchScreen故事板上不能有一个自定义类。所以我的问题是,有没有办法以编程方式编写LaunchScreen代码,因为我希望避免使用IB在它上面拖放元素。
发布于 2015-09-30 00:09:59
不,在你的应用程序开始执行之前会显示启动屏幕,以便在应用程序加载时提供从Springboard到应用程序的过渡。
您可以使用固定的图像,也可以仅使用标准的静态UI元素-标签和图像-使用简单的故事板场景。
这个故事板场景实际上是由操作系统加载和显示的,因此允许您的代码在该上下文中执行将是一个安全风险。
发布于 2021-03-25 12:37:52
这并不是真正意义上的编程,因为它只是编辑info.plist文件,但是,根据我的研究,我发现引入了一种新方法,特别是现在的SwiftUI,以及它将如何取代我发现的StoryBoards here
我想在这里分享给那些搜索这个话题并第一次接触到这篇文章的人,他们只是想用一种不同于使用StoryBoards创建启动屏幕的方式(像我一样)。
发布于 2018-09-08 07:38:02
它成功工作了
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
}
https://stackoverflow.com/questions/32855526
复制