Swift - 在 AppDelegate 中添加子视图
Swift - adding Subview in AppDelegate
我对 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
}
问题出在事件的顺序上。您添加启动视图。然后根视图控制器出现并获取它的视图并将其添加到 window — 覆盖启动视图。
一种解决方法是让根视图控制器现在获取它的视图,并将初始视图放在那个视图中:
window?.rootViewController?.view.addSubview(revealingSplashView)
我对 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
}
问题出在事件的顺序上。您添加启动视图。然后根视图控制器出现并获取它的视图并将其添加到 window — 覆盖启动视图。
一种解决方法是让根视图控制器现在获取它的视图,并将初始视图放在那个视图中:
window?.rootViewController?.view.addSubview(revealingSplashView)