4
5

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 3 years have passed since last update.

SwiftUIから自身のUIHostringViewControllerをdismissする

Last updated at Posted at 2021-11-28

iOS15から、EnvironmentValuesにdismissが追加されました。
これまでUIKitのアプリ内からSwiftUIのモーダルを表示してから閉じるにはハックが必要でしたが、これによって簡単に閉じられるようになります。

struct ContentView: View {
  @Environment(\.dismiss) var dismiss
                
  var body: some View {
    Button {
      dismiss()
    } label: {
      Text("dismiss")
    }
  }
}

UIKitベースのアプリの中に1画面だけSwiftUIにすることがこれで簡単に行えるようになりました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?