1
1

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.

iOS14でSwiftUIのモーダル表示がズレる問題の対応

Posted at

背景

シンプルな音楽プレイヤーアプリをフルSwiftUIで作ったものがあるのですが、Xcode12のせいなのか、iOS14のせいなのかわからなのですが、モーダル表示がずれてしまいました。
Download on the App Store

iOS13 Xcode 11 iOS 14 Xcode 12
IMG_7874.PNG IMG_7873.PNG

この画面の構成は以下の通りとなっています。

var body: some View {
    GeometryReader { geometry in
        ZStack {
            VStack (spacing: 0) {
                   ....... 各パーツ .......
            }
        }
    }
}

解決策

対象のViewにframe(width: CGFlaot)を設定することで解消されました。

var body: some View {
    GeometryReader { geometry in
        ZStack {
            VStack (spacing: 0) {
                   ....... 各パーツ .......
            }
            // 以下を追加
            .frame(width: geometry.size.width)
        }
    }
}

この現象は今の所、モーダルでしか見つかっていないのでSwiftUI 2.0でそこらへんの修正があったのかもしれませんね。

 宣伝

自分のアプリダウンロードしていただけたら幸いです。
https://apple.co/37okj2G

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?