7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[swift].showで画面遷移を横スライドにする

Posted at

.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)
}

エミュレータを立ち上げて実行すると遷移のアニメーションが横スライドになってると思います。

7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?