快速-在AppDelegate中添加子视图

问题描述 投票:0回答:1

我对revealingSplashView有问题。我希望每次启动应用程序时都显示它,但是由于我必须将其添加为Subview,所以不显示它,但是我该如何在AppDelegate中添加它呢?

我尝试了这个,但是没有用:

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
}
ios swift uiview appdelegate subview
1个回答
1
投票

问题是事件的顺序。您添加初始视图。然后,根视图控制器随即出现并获取其视图,并将其添加到窗口中-覆盖初始视图。

一种解决方法是使根视图控制器获取其视图now并将启动视图置于that视图中:

window?.rootViewController?.view.addSubview(revealingSplashView)
© www.soinside.com 2019 - 2024. All rights reserved.