下のように、UIViewControllerをpresentした時の挙動を変更してみました。
present(UIViewController(), animated: true, completion: nil)
present時のアニメーションですが、デフォルトでは下の4つが用意されています。
public enum UIModalTransitionStyle : Int { case coverVertical case flipHorizontal case crossDissolve @available(iOS 3.2, *) case partialCurl }
下のように、UIViewControllerを2つ作って動きを確認してみました。
class ViewController1: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.lightGray.withAlphaComponent(0.5) navigationItem.leftBarButtonItem = UIBarButtonItem(title: "遷移", style: .plain, target: self, action: #selector(self.showViewController2)) } func showViewController2() { let vc = ViewController2() vc.modalTransitionStyle = .crossDissolve present(vc, animated: true, completion: nil) } } class ViewController2: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.blue.withAlphaComponent(0.5) } }
coverVertical
modalTransitionStyleでデフォルトで指定されているアニメーションです。
表示する画面が、下から出てきます。
わかり易さのためにアニメーション速度を落として遷移しています。
flipHorizontal
ビューが回転して出てくるアニメーションです。
crossDissolve
今表示されている画面がフェードアウトしていき、次に表示する画面が段々フェードインするアニメーションです。
partialCurl
紙のページをめくるようなアニメーションです。