Swift - adding Subview in AppDelegate

て烟熏妆下的殇ゞ 提交于 2021-01-29 18:55:02

问题


I have a problem with revealingSplashView. I want it to be shown every time the app launches but it is not being displayed because I have to add it as a Subview but how can I do that inside AppDelegate?

I tried this but it is not working:

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

let revealingSplashView = RevealingSplashView(iconImage: UIImage(named: "zauberstab")!, iconInitialSize: CGSize(width: 120, height: 120), backgroundColor: .white)

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    print("hi")
    revealingSplashView.startAnimation()
    window?.addSubview(revealingSplashView)
    FirebaseApp.configure()

    return true
}

回答1:


The problem is the order of events. You add the splash view. Then the root view controller comes along and gets its view and adds that to the window — covering the splash view.

One workaround is to make the root view controller get its view now and put the splash view in that view:

window?.rootViewController?.view.addSubview(revealingSplashView)


来源:https://stackoverflow.com/questions/59904854/swift-adding-subview-in-appdelegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!