LoginSignup
0
1

More than 3 years have passed since last update.

window.rootViewController入れ替え時のアニメーション

Posted at

重要な点は、UIView.transitionanimationsでViewControllerの入れ替えをするのではなく、先に入れ替え処理を書いてからUIView.transitionを呼び出すこと。(animations引数は空のクロージャ。)

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    ...

    func setRootViewController(_ vc: UIViewController) {
        guard let window = window else {
            return
        }
        window.rootViewController = vc
        UIView.transition(
            with: window,
            duration: 0.5,
            options: .transitionFlipFromLeft,
            animations: {},
            completion: { _ in })
    }

}

こんな感じでアニメーションさせられます。

アニメーションの種類は他にもあるので .transitionFlipFromLeft に定義ジャンプして確認してみてください。

ページ送りやフェードのアニメーションもできます。

参考

Swap rootViewController with animation?

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1