3
votes

I have a shared view in my app that can be called in different places. The root of this view is a scroll view, but sometimes it ignores the top safe area and it collapses under the navigation bar.

Here two screenshots that shows better the problem:

enter image description here enter image description here

As you can see in the second screenshot the scrollview extends for all the screen collapsing under the navigation. How can I avoid this?

3
provide trial code.Sagar Bhut
can't provide the code due to privacy, but i've fixed with .navigationViewStyle(StackNavigationViewStyle())Andrea Miotto

3 Answers

10
votes

Adding .padding(.top, 1) to the scroll view will solve the issue.

3
votes

Solved using:

.navigationViewStyle(StackNavigationViewStyle())

in all the NavigationView

0
votes

You can solved it by giving padding to scroll view

ScrollView {
    VStack(spacing: 0) {
      
        Text("test")
        Text("test")
        Text("test")
        Text("test")
        Text("test")
        
    }
}
.padding(.top, UIApplication.shared.windows.first!.safeAreaInsets.top )