2
1

【iOS】iPhoneでもpopoverを吹き出しにする方法【SwiftUI】

Last updated at Posted at 2023-11-07

はじめに

左みたいなポップアップを出したいだけだったのに、かなりハマったので備忘録。
調べて出てくるpopoverの見た目と手元の環境での見た目(右)がまるで違う。昔は左がデフォルトだったのだろう。

結論

  1. デプロイの設定をiOS 16.4以上にする。
  2. .presentationCompactAdaptation(.none)をつける。
var body: some View {
    @State var popoverVisible = true

    VStack {
        // メインコンテンツ
        ...
    }
    .popover(isPresented: popoverVisible, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) {
        Text("text")
            .presentationCompactAdaptation(.none)
    }
}

参考文献

おわりに

一つ目の記事のHow to set the size and location of a popover in SwiftUI?でかなりサラッと書かれている。
日本語で調べた限りだと解決に繋がる記事は見つからなかった。
iOS(swift)ってポップアップ系のUIこれしかないと思っているのだが、みんな必要としてなかったり別の何かが存在したりするんだろうか。

2
1
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
2
1