问题
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