Swift - 在 AppDelegate 中添加子视图 [英] Swift - adding Subview in AppDelegate
问题描述
我对 revealingSplashView 有问题.我希望每次应用程序启动时都显示它,但它没有显示,因为我必须将它添加为 Subview
但我如何在 AppDelegate
中执行此操作?
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
}
推荐答案
问题是事件的顺序.您添加启动视图.然后根视图控制器出现并获取其视图并将其添加到窗口 - 覆盖初始视图.
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)
这篇关于Swift - 在 AppDelegate 中添加子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!