Is there any way to code the LaunchScreen programmatically

前端 未结 2 708
遇见更好的自我
遇见更好的自我 2020-12-10 12:26

I am using Xcode7 and Swift with Storyboards. When I open the LaunchScreen.storyboard, and I try to set a Custom Class on it, Xcode complains that one cannot have a custom c

相关标签:
2条回答
  • 2020-12-10 12:31

    No, The launch screen is shown before your app starts executing in order to provide a transition from the Springboard to your app while it is loading.

    You can either use a fixed image or you can use a simple storyboard scene using only standard, static UI elements - labels & images.

    This storyboard scene is actually loaded and displayed by the OS, so it would be a security risk to allow your code to execute in that context.

    0 讨论(0)
  • 2020-12-10 12:33

    It works successfully

    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
    }
    
    0 讨论(0)
提交回复
热议问题