70 lines
2.4 KiB
Swift
70 lines
2.4 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 titleLabel = UILabel()
|
|
titleLabel.text = "젤리의 적자탈출"
|
|
titleLabel.font = UIFont.boldSystemFont(ofSize: 36)
|
|
titleLabel.textAlignment = .center
|
|
titleLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
if let splashView = splashView {
|
|
self.view.addSubview(splashView)
|
|
splashView.addSubview(titleLabel)
|
|
|
|
NSLayoutConstraint.activate([
|
|
titleLabel.centerXAnchor.constraint(equalTo: splashView.centerXAnchor),
|
|
titleLabel.centerYAnchor.constraint(equalTo: splashView.centerYAnchor)
|
|
])
|
|
}
|
|
}
|
|
|
|
@objc private func webViewDidFinishLoad() {
|
|
// 웹뷰 로드 완료 시 스플래시 화면 제거
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
|
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)
|
|
|
|
// 웹뷰 로드 시작 시 스크립트 실행
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 5.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
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|