This is the content view which moves down on the screen as I open it from different view.
when I click top left button to open menu.
The menu
When I click the Home option from menu whole view moves down on screen.
The whole view gets moved down on screen each time I open it.
//the content view
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView{
ScrollView{
Text("Men")
.font(.system(size: 30, weight:.bold))
.padding(.trailing, 320.0)
ScrollView(.horizontal){
HStack{
NavigationLink(destination:mentshirt()){
custom(content:Image("mentshirt"),over:"T-shirt",col: .black)
}
NavigationLink(destination:menjeans()){
custom(content:Image("menjeans"),over:"Jeans",col: .black)
}
NavigationLink(destination:menjacket()){
custom(content:Image("menjacket"),over: "Jacket",col: .black)
}
}
}
Text("Women")
.font(.system(size: 30,weight: .bold))
.padding(.trailing,280.0)
ScrollView(.horizontal){
HStack{
NavigationLink(destination:womentshirt()){
custom(content:Image("womentshirt"),over:"T-shirt",col: .black)
}
NavigationLink(destination:womenjeans()){
custom(content:Image("womenjeans"),over:"Jeans",col: .black)
}
NavigationLink(destination:womenjacket()){
custom(content:Image("womenjacket"),over:"Jacket",col: .black)
}
}
}
Text("Kids")
.font(.system(size: 30,weight: .bold))
.padding(.trailing,320.0)
ScrollView(.horizontal){
HStack{
NavigationLink(destination:kidtshirt()){
custom(content:Image("kidtshirt"),over:"T-shirt",col:.black)
}
NavigationLink(destination:kidjeans()){
custom(content:Image("kidjeans"),over:"Jeans",col: .black)
}
NavigationLink(destination:kidjacket()){
custom(content:Image("kidjacket"),over:"Jacket",col:.black)
}
}
}
}
.navigationBarBackButtonHidden(true)
.navigationBarItems(leading:
NavigationLink(
destination: clothlist()){
navcustom(content:
Image(systemName: "line.horizontal.3"),col: .white)
},
trailing:
HStack{
Image("logo")
.resizable()
.clipShape(Circle())
.shadow(color:.white,radius: 10)
.frame(width: 30, height: 30, alignment: .center)
Spacer(minLength: 80)
NavigationLink(destination: cart()){
navcustom(content:
Image(systemName: "cart"),col: .white)
}
Spacer(minLength: 15)
NavigationLink(destination: login()){
navcustom(content:Image(systemName: "person.crop.circle.fill"), col: .white)
}
}
)
}.navigationBarBackButtonHidden(true)
.ignoresSafeArea()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView()
.environment(\.colorScheme, .dark)
}
}
}
func custom(content:Image,over:String,col:Color) -> some View {
content
.resizable()
.overlay(Text(over).font(.system(size: 20,weight: .bold)).foregroundColor(col),alignment: .bottomLeading)
.frame(width: 400, height: 500, alignment: .center)
.padding(5)
}
func navcustom(content:Image,col:Color)-> some View {
content
.resizable()
.frame(width: 30, height: 30, alignment: .center)
.foregroundColor(col)
}
//the menu view from which I open content view
import SwiftUI
struct clothlist: View {
var body: some View {
List
{
NavigationLink(destination:ContentView())
{
Text(Image(systemName: "house"))+Text(" Home")
}
Text(Image(systemName: "person"))+Text(" Men")
NavigationLink(destination:menjeans())
{
Text("Jeans")
}
NavigationLink(destination:menjacket())
{
Text("Jacket")
}
NavigationLink(destination:mentshirt())
{
Text("Tshirt")
}
Text(Image(systemName: "person"))+Text(" Women")
NavigationLink(destination:womenjeans())
{
Text("Jeans")
}
NavigationLink(destination:womenjacket())
{
Text("Jacket")
}
NavigationLink(destination:womentshirt())
{
Text("Tshirt")
}
Group{
Text(Image(systemName: "person"))+Text(" Kids")
NavigationLink(destination:kidjeans())
{
Text("Jeans")
}
NavigationLink(destination:kidjacket())
{
Text("Jacket")
}
NavigationLink(destination:kidtshirt())
{
Text("Tshirt")
}
}
}
.navigationBarBackButtonHidden(true)
}
}
struct clothlist_Previews: PreviewProvider {
static var previews: some View {
clothlist()
}
}
how to stop the view from moving down on screen on every open?