在我的应用程序中,我使用的是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
复制到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在此问题中回答了该问题:adding Subview in AppDelegate
关于ios - Swift-无论哪个ViewController启动,在应用启动时都显示showingSplashView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59899464/