[英]Swift - adding Subview in AppDelegate
我有一個揭示SplashView的問題。 我希望每次應用程序啟動時都顯示它,但它沒有顯示,因為我必須將它添加為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
}
問題是事件的順序。 您添加啟動視圖。 然后根視圖控制器出現並獲取它的視圖並將其添加到窗口 - 覆蓋初始視圖。
一個解決辦法是讓根視圖控制器現在得到其觀點,把濺鑒於這種觀點:
window?.rootViewController?.view.addSubview(revealingSplashView)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.