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.

2

3 Answers 3

4

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

.navigationBarTitle(Text(""), displayMode: .inline)
Sign up to request clarification or add additional context in comments.

1 Comment

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?
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
           }
        }
    }

Comments

1

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

.navigationBarTitle("")
.navigationBarHidden(true)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.