有没有办法以编程方式编码LaunchScreen

问题描述 投票:10回答:2

我正在使用Xcode7和Swift与Storyboard。当我打开LaunchScreen.storyboard,并尝试在其上设置自定义类时,Xcode抱怨在LaunchScreen故事板上不能有自定义类。所以我的问题是,有没有办法以编程方式对LaunchScreen进行编码,因为我希望避免使用IB拖放元素。

ios objective-c swift xcode7
2个回答
24
投票

不,在应用程序开始执行之前会显示启动屏幕,以便在加载时提供从Springboard到应用程序的转换。

您可以使用固定图像,也可以仅使用标准的静态UI元素(标签和图像)来使用简单的故事板场景。

这个故事板场景实际上是由操作系统加载和显示的,因此允许代码在该上下文中执行会带来安全风险。


-2
投票

它运作成功

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
}
© www.soinside.com 2019 - 2024. All rights reserved.