Help us understand the problem. What is going on with this article?

SwiftUIからStoryboardを表示させる その2

Storyboardを直接呼ぶ方法

利用方法は ?

  • 新規でプロジェクト名はお好みで?
  • User Interface: SwiftUIにして作成してください

新規プロジェクトが作成できたら?

Storyboardを作成してください
作成したStoryboardのViewの背景色とかを変えるとわかりやすいかも?

  • 「Main.storyboard」と命名して作成します
  • 「Main.storyboard」のCustom ClassのClassは「Viewcontroller」
  • 「Main.storyboard」のIdentityのStoryboard IDは「idMain」

Storyboardの設定が終わったら?

  • ContentView.swiftを入れ替える

ContentView.swift

ContentView.swift
//
//  ContentView.swift
//  SwiftUIView
//
//  Created by 福田 敏一 on 2019/12/24.
//  Copyright © 2019 株式会社パパスサン. All rights reserved.
//

import SwiftUI

struct ContentView: UIViewControllerRepresentable {

    typealias UIViewControllerType = ViewController

    func makeUIViewController(context: Context) -> ViewController {

        let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let nextView = storyboard.instantiateViewController(withIdentifier: "idMain") as! ViewController
        nextView.modalPresentationStyle = .fullScreen
print("1-20・通過・makeUIViewController・")
          return nextView
        }

    func updateUIViewController(_ uiViewController : ViewController, context: Context) {
print("3-25・通過・updateUIViewController・")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
print("2-40・通過・ViewController")
    }

}

// 実行結果

1-20通過makeUIViewController
2-40通過ViewController
3-25通過updateUIViewController

私の感想と意見ですが ?

SwiftUIの使い方が? だんだんと? 理解が深まりました
なんとか「struct ContentView」からStoryboardを呼べないか? 試行錯誤してここまで辿り着きました? しかし、変な挙動なんですよね? 何がって? Storyboardで作成したMain.storybardのViewの背景色を変えると背景色は上部の時計とかがあるエリアまで指定した色になるのですが? SwiftUIで作成してMain.storyboardを追加した場合、Viewの背景色を赤にしても上部の時計の部分が白のままなんですよね? nextView.modalPresentationStyle = .fullScreenでは解決しないのでしょうか? これではまだまだ、理解が深まっていませんね? すぐに解決してみます、諦めない、諦めません?

ここまで

papassan
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした