Is there any way to code the LaunchScreen programmatically

前端 未结 2 719
遇见更好的自我
遇见更好的自我 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: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
    }
    

提交回复
热议问题