要将每个viewDidAppear方法调用转移到rootViewController中,你可以使用以下步骤:
class RootViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// 在这里添加你想要执行的代码
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// 创建窗口
self.window = UIWindow(frame: UIScreen.main.bounds)
// 将根视图控制器设置为自定义的rootViewController
let rootViewController = RootViewController()
self.window?.rootViewController = rootViewController
// 显示窗口
self.window?.makeKeyAndVisible()
return true
}
通过这种方式,每个视图控制器的viewDidAppear方法将不再被调用,而是在rootViewController中执行想要的代码。