.showの画面遷移方法を変えるというよりはViewをNavigationControllerにしてしまおうというような記事です。
自分も初心者なのでフィードバックなどいただけたらありがたいです。
ViewをnavigationControllerにする
通常showで遷移する場合は下から画面が出てくるようなアニメーションになりますがnavigationController上でshowをすると右から画面が出てくるようなアニメーションになります
プロジェクトのAppDelegate.swiftのApplicationの中に以下のコードを記入すると最初の画面がNavigationControllerになります。
AppDelefate.swift
func application(_ application: ~~~Bool {
let navigationController = UINavigationController(rootViewController: UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "initView"))
self.window?.rootViewVontroller = navigationController
return true
}
Identifierが"initView"なViewを最初に画面として呼び出しています。
ではVIewControllerに遷移のコードを記入していきます。
InitViewController.swift
@IBAction func nextButton(_ sender: Any) {
let nextView = self.storyboard!.instantiateViewController(withIdentifier: "nextView"
self.show(nextView, sender: nil)
}
エミュレータを立ち上げて実行すると遷移のアニメーションが横スライドになってると思います。