2

I currently have a modal view in SwiftUI that contains a series of NavigationLinks to different views. However, when I go to one of the other views it pushes all the content down leaving a empty forehead at the top of the view. How do I fix this? I have included an example screenshot below.

enter image description here

To further clarify, there is a main view with a button that opens a Modal view. This modal contains a navigation view with a series of NavigationLink Buttons. When opening the navigation links within the modal, that is when the view is pushed down.

Thomas Braun
  • 1,109
  • 2
  • 13
  • 27

3 Answers3

4

You have a large navigation bar, try to set navigationBar displayMode to .inline

.navigationBarTitle(Text(""), displayMode: .inline)
Sorin Lica
  • 6,894
  • 10
  • 35
  • 68
  • I tried this, and while it did center my views back to normal, it added a top bar with a different background color than the view it was in. Is there an easy way to avoid this behavior? – ty1 Mar 29 '20 at 04:02
4

This probably happens because the view you push to from the NavigationView is also wrapped in a NavigationView.

struct SettingsView: View {
    var body: some View {
        NavigationView {
           NavigationLink(destination: IAPView()) {
               Text("In App Purchase")
           }
       }
    }
}

You probably have this in the IAPView()

struct IAPView: View {
        var body: some View {
            NavigationView { <-- this is causing it
               // your buttons here
           }
        }
    }
Jordi Bruin
  • 1,588
  • 1
  • 11
  • 20
1

You still have the default navigation bar space in your view. You need to add both these two view modifiers.

.navigationBarTitle("")
.navigationBarHidden(true)
Audrey Sobgou Zebaze
  • 2,840
  • 2
  • 19
  • 9