![見出し画像](https://assets.st-note.com/production/uploads/images/101349652/rectangle_large_type_2_64fcf8ae0360a521b2d5ad7ff8a7ec42.png?width=1200)
【徒然iOS】気ままにUIKit74〜Segue シーンとシーン接続して画面遷移〜
概要
このマガジンは四十を過ぎたおっさんが、
を参考にStoryboardでiOSアプリを完全に趣味で楽しんでいるだけな記事を気ままに上げてます。
今回
をハイ、レッツゴ🕺
前々回で、ボタンを配置して、各ビューを繋いでたアレの、
Navigation Controllerのないバージョンと思っていただけると〜〜〜〜💦
前準備
念の為、
バックアップ
新しいクラス
ビューコントローラの追加
イニシャルビューの変更
をいつも通りやってから本題へ💃
![](https://assets.st-note.com/img/1679961455954-IiLvrmzNmZ.png?width=1200)
本題
Segueとは
シーンとシーンを接続し画面遷移を行うための部品
前々回ですでにやってるから、すでにSegueがいっぱい💦
⒈もう一個、ビューを配置して、色を変えて、ボタンを配置
![](https://assets.st-note.com/img/1679961989934-pt2Fupv3zE.png?width=1200)
![](https://assets.st-note.com/img/1679962095806-GJdA0q6yxZ.png?width=1200)
![](https://assets.st-note.com/img/1679962169794-jA5uJkTA7s.png?width=1200)
⒉ドラッグしてModalを選択
![](https://assets.st-note.com/img/1679962249685-fX0rXGoseg.png?width=1200)
ので、Present Modallyってのを選んで
![](https://assets.st-note.com/img/1679962299225-ZXxLn3xSre.png?width=1200)
とりあえず、SizeClassもチェックを入れとこう
![](https://assets.st-note.com/img/1679962427870-F3xsMilA9e.png?width=1200)
おそらくTraitVariationだな💦
⒊シミュレータを実行
![](https://assets.st-note.com/img/1679962622273-MX8Jp6WM96.png?width=1200)
![](https://assets.st-note.com/img/1679962636745-m5yUthbDEA.png?width=1200)
っと、ここでサイト記事と色が逆なので〜〜〜〜
![](https://assets.st-note.com/img/1679962700874-EAzeEoxil5.png?width=1200)
⒋コード組み込み
//青画面に戻るときの呼び出しメソッド
@IBAction func prevGamen(segue: UIStoryboardSegue) {
//処理無し
}
を組み込めと言ってるようなので、、、
![](https://assets.st-note.com/img/1679962854503-QLHp7jWr3t.png?width=1200)
![](https://assets.st-note.com/img/1679962923821-y1CcFzCKN0.png?width=1200)
![](https://assets.st-note.com/img/1679962971798-VMfljPqpOw.png?width=1200)
![](https://assets.st-note.com/img/1679963000988-5fYmjo5G5d.png?width=1200)
⒌条件によって、遷移先を変更
![](https://assets.st-note.com/img/1679963155189-e2ANhtG9vG.png)
![](https://assets.st-note.com/img/1679963188818-oogOWJUPmG.png?width=1200)
![](https://assets.st-note.com/img/1679963264672-JlDY8xLqVT.png?width=1200)
![](https://assets.st-note.com/img/1679963560585-c29aEtJ6Li.png?width=1200)
![](https://assets.st-note.com/img/1679963581191-4NNQEyo7ie.png?width=1200)
![](https://assets.st-note.com/img/1679963601471-CMNh38soOE.png?width=1200)
![](https://assets.st-note.com/img/1679963632487-acBOARtCeL.png?width=1200)
![](https://assets.st-note.com/img/1679963681249-VKsAgctMwX.png?width=1200)
![](https://assets.st-note.com/img/1679963780438-pec8ilh6uh.png?width=1200)
![](https://assets.st-note.com/img/1679963914867-y3ccJSZBr8.png?width=1200)
⒍次へボタンをアクション接続
![](https://assets.st-note.com/img/1679964110845-PuCbWCng2w.png?width=1200)
![](https://assets.st-note.com/img/1679964128740-f2PrS9LDbP.png?width=1200)
⒎コード組み込み
//
// ViewController.swift
//
import UIKit
class ViewController: UIViewController {
//最初からあるメソッド
override func viewDidLoad() {
super.viewDidLoad()
}
//青画面に戻るときの呼び出しメソッド
@IBAction func prevGamen(segue: UIStoryboardSegue) {
//処理無し
}
//ボタンドラッグ時の呼び出しメソッド
@IBAction func dragExit(sender: UIButton) {
//識別子「GreenSegue」のセグエを実行する。
performSegueWithIdentifier("GreenSegue", sender: nil)
}
//ボタンダブルタップ時の呼び出しメソッド
@IBAction func doubleTap(sender: UIButton) {
//識別子「YellowSegue」のセグエを実行する。
performSegueWithIdentifier("YellowSegue", sender: nil)
}
}
⒏シミュレータ実行
![](https://assets.st-note.com/img/1679964360083-RzYQke4SUe.png?width=1200)
![](https://assets.st-note.com/img/1679964376637-fNzWtLZqep.png?width=1200)
サイト記事としては、以上🕺
ブラッシュアップ
AutoLayoutだけやっとこう
![](https://assets.st-note.com/img/1679964594936-IjqjZpnzDa.png?width=1200)
![](https://assets.st-note.com/img/1679964624250-jypL1bxxmu.png?width=1200)
![](https://assets.st-note.com/img/1679964643870-wCRT7zWWHq.png?width=1200)
![](https://assets.st-note.com/img/1679964680307-hu8fvzIaRg.png?width=1200)
今回のコード(まとめ)
class SegueStandardViewController: UIViewController {
//最初からあるメソッド
override func viewDidLoad() {
super.viewDidLoad()
}
//青画面に戻るときの呼び出しメソッド
@IBAction func prevGamen(segue: UIStoryboardSegue) {
//処理無し
}
//ボタンドラッグ時の呼び出しメソッド
@IBAction func myDragExit(_ sender: UIButton) {
//識別子「GreenSegue」のセグエを実行する。
performSegue(withIdentifier: "GreenSegue", sender: nil)
}
//ボタンダブルタップ時の呼び出しメソッド
@IBAction func myDoubleTap(_ sender: UIButton) {
//識別子「YellowSegue」のセグエを実行する。
performSegue(withIdentifier: "OrangeSegue", sender: nil)
}
}
ちょっと試しに、、、
NavigationControllerと今回の青画面を繋いでみよう👀
どうなるかドキドキ💦
![](https://assets.st-note.com/img/1679965082574-lFrYHYa7oX.png?width=1200)
Showに〜〜〜
![](https://assets.st-note.com/img/1679965112143-timtY2Wiu7.png?width=1200)
![](https://assets.st-note.com/img/1679965152967-Ubf9ZaoNtP.png?width=1200)
![](https://assets.st-note.com/img/1679965168645-HXRM5Fnzdh.png?width=1200)
![](https://assets.st-note.com/img/1679965259861-ZCdOUskuct.png?width=1200)
![](https://assets.st-note.com/img/1679965285061-LqU8A7FpQy.png?width=1200)
![](https://assets.st-note.com/img/1679965341878-sgKbfFZJMC.png?width=1200)
![](https://assets.st-note.com/img/1679965412847-dJQqHO5M12.png?width=1200)
他のも試してみたけど、結果は同じ。なんかNavigationControllerと詳細なSegueは、
思ったとおり、相性悪いね藁🤣
たしか、Customでハンドラーを使うとできた気がするけど、
この記事の趣旨と反するので、
💃残りの記事を一旦、進めよ🕺
Apple公式
さて、次回は
をレッツゴする🕺