ios - Swift - 无论哪个 ViewController 在应用程序启动时显示revealingSplashView
问题描述
在我的应用程序中,我使用了revealingSplashView。
用户既可以登录,也可以ViewController
更改开始:
class MainNavigationControllerViewController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
if isLoggedIn() {
let homeController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeVC")
viewControllers = [homeController]
}
}
fileprivate func isLoggedIn() -> Bool {
return UserDefaults.standard.isLoggedIn()
}
}
或者用户未登录,因此FirstLaunchViewController
正在显示用户可以登录和访问的位置MainViewController
。
目前我是这样介绍revealingSplashView
的FirstLaunchViewController
:
let revealingSplashView = RevealingSplashView(iconImage: UIImage(named: "zauberstab")!, iconInitialSize: CGSize(width: 120, height: 120), backgroundColor: .white)
revealingSplashView.startAnimation()
问题是,如果用户已登录,我也希望拥有该动画,因此MainViewController
启动 VC 也是如此。我知道我可以将代码从FirstLaunchViewController
to复制,MainViewController
但是当用户登录并进入MainViewController
正在显示的动画时,这会导致问题,即使它应该只在应用程序启动后显示。
解决方案
像@chirag90 建议的解决方案是将代码移入AppDelegate
如下didFinishLaunchingWithOptions
:
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.
revealingSplashView.startAnimation()
window?.rootViewController?.view.addSubview(revealingSplashView)
return true
}
出现的另一个问题是如何添加reavelingSplashView
一个Subview
@matt 在这个问题中回答的问题:
推荐阅读
- cmake - 在 Embarcadero 中使用 CMake
- gradle - Gradle 的子项目依赖项失败
- python - 将数据帧写入 csv 时出错
- c# - 如何使用 jquery 设置 aspnet 下拉列表的选定值
- python - 累积和结转 - 用 pandas 向量化
- rest - 如何访问 Alexa 上本地托管的 REST API
- excel - Excel Web 加载项:如何检测功能区单击事件?
- sql-server - 用于更改现有数据库的 SQL Server 数据库项目
- visual-studio-code - VSCode 扩展不显示贡献
- python - PyCharm 在优化导入时将 os 视为第三方模块