【问题标题】:Swift - adding Subview in AppDelegateSwift - 在 AppDelegate 中添加子视图
【发布时间】:2020-05-11 06:39:23
【问题描述】:

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?.rootViewController?.view.addSubview(revealingSplashView)?
  • 工作就像一个魅力,谢谢:)
  • 酷,我会给出这个答案。

标签: ios swift uiview appdelegate subview


【解决方案1】:

问题在于事件的顺序。您添加启动视图。然后根视图控制器出现并获取它的视图并将其添加到窗口 - 覆盖启动视图。

一种解决方法是让根视图控制器现在获取它的视图并将启动视图放在那个视图中:

window?.rootViewController?.view.addSubview(revealingSplashView)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    • 1970-01-01
    相关资源
    最近更新 更多