Files
zellyy-finance/ios/App/App/ViewController.swift

70 lines
2.5 KiB
Swift

import UIKit
import Capacitor
import WebKit
class ViewController: CAPBridgeViewController {
private var splashView: UIView?
override func viewDidLoad() {
super.viewDidLoad()
//
setupSplashView()
//
NotificationCenter.default.addObserver(self, selector: #selector(webViewDidFinishLoad), name: NSNotification.Name(rawValue: "capacitorWebViewDidLoad"), object: nil)
}
private func setupSplashView() {
//
splashView = UIView(frame: self.view.bounds)
splashView?.backgroundColor = UIColor.white
//
let imageView = UIImageView(image: UIImage(named: "Splash"))
imageView.contentMode = .scaleAspectFit
imageView.translatesAutoresizingMaskIntoConstraints = false
if let splashView = splashView {
self.view.addSubview(splashView)
splashView.addSubview(imageView)
NSLayoutConstraint.activate([
imageView.centerXAnchor.constraint(equalTo: splashView.centerXAnchor),
imageView.centerYAnchor.constraint(equalTo: splashView.centerYAnchor),
imageView.widthAnchor.constraint(equalToConstant: 200),
imageView.heightAnchor.constraint(equalToConstant: 200)
])
}
}
@objc private func webViewDidFinishLoad() {
// (2 )
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
UIView.animate(withDuration: 0.3, animations: {
self.splashView?.alpha = 0
}, completion: { _ in
self.splashView?.removeFromSuperview()
self.splashView = nil
})
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// ( 2 )
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
if self.splashView != nil && self.splashView?.alpha == 1 {
UIView.animate(withDuration: 0.3, animations: {
self.splashView?.alpha = 0
}, completion: { _ in
self.splashView?.removeFromSuperview()
self.splashView = nil
})
}
}
}
}