ios - Swift-无论哪个ViewController启动,在应用启动时都显示showingSplashView

标签 ios swift animation uiview uiviewcontroller

在我的应用程序中,我使用的是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/

相关文章:

ios - WatchOS 2 并发症计划在后台更新

ios - Firebase,离开我的调试器控制台

python - 当我点击移动时,如何为 pygame 角色行走设置动画

iphone - UIImageView介绍动画问题

css - 动画在旧 iPad Webkit 上消失

ios - 如何在框架中获取Viewcontroller引用

objective-c - 更改““YourApp”要使用您当前位置”的语言

ios - Swift:如何以编程方式更改 View 的位置?

iphone - 每次我的应用程序从后台进入前台时显示 IOS Default.png

ios - iOS 7 的动态表格 View 单元格高度