swift 3を使用して、アプリケーションのスプラッシュ画面としてストーリーボードからビューコントローラーを作成しようとしています。「画像の起動」を使用してスプラッシュを読み込んでいるときに、スプラッシュ画面と同じ効果を達成しようとしています。スプラッシュ画面にアニメーションがあるので、Swift 3のスプラッシュ画面としてビューコントローラーを使用したいと思います。これを実現するにはどうすればよいですか?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "splashScreen")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
return true
}
スプラッシュ画面を備えたrootViewControllerとしてViewControllerを作成し、そのView Controllerを2〜3秒表示してみてください。最初のViewControllerをプッシュ/提示します。
この方法でスプラッシュViewControllerを設定できます:-
self.window?.rootViewController = splashVC
sparkVCのViewDidLoad()で、タイマーまたは遅延を使用し、2〜3秒後に使用します。アプリケーションのメインのViewControllerを表示します。
//MARK:- Life Cycle Methods
override func viewDidLoad() {
super.viewDidLoad()
Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.splashTimeOut(sender:)), userInfo: nil, repeats: false)
// Do any additional setup after loading the view.
}
func splashTimeOut(sender : Timer){
AppDelegate.sharedInstance().window?.rootViewController = yourCustomViewController
}
あなたの便宜のためにAppdelegateにこのメソッドを追加してください:-
class func sharedInstance() -> AppDelegate{
return UIApplication.shared.delegate as! AppDelegate
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加