Swift-在AppDelegate中添加子视图 [英] Swift - adding Subview in AppDelegate

查看:103
本文介绍了Swift-在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆