在没有导航视图的视图之间切换

时间:2020-08-17 14:55:22

标签: swiftui navigationview swiftui-navigationlink swiftui-button

我正在尝试做到这一点,因此,当我单击用户名按钮时,会弹出一个新视图,全屏显示我为用户名视图创建的视图。我已经尝试过navigationView,但是我不喜欢标题显示在主视图中。我试过使用可以正常工作的工作表,但它不能覆盖整个屏幕。有什么办法可以在我喜欢的MainScreen.swift,Username.swift和Data.swift之类的不同视图之间切换 谢谢!

//Creating booleans to show sheets of different menus
@State var showUser: Bool = false
@State var showData: Bool = false


var body: some View {
    //Making
    ScrollView(.vertical){
        VStack{
            //User button
           
                Button(action: {
                    withAnimation{
                        self.showUser = true
                    }
                })
                {
                    // Creating Hstack for name of button and image
                    HStack{
                        //Text of button
                        Text("Username")
                            .font(.custom("Futura", size: 17))
                            .fontWeight(.ultraLight)
                        //Image of button
                        Image(systemName: "person.crop.circle.fill")
                        
                    } //Hstack
                        .aspectRatio(contentMode: .fit)
                        .frame(minWidth: 0, maxWidth: 300)
                        .padding()
                        .background(RoundedRectangle(cornerRadius: 10).stroke(Color.blue, lineWidth: 2))
                        .padding(.top, 5)
                        .padding(.bottom, 5)
                    
                    //username button settings
                } //user button
        
        
        
                //Data button
                if showData {
                    Data()
                        .animation(.spring())
                        .transition(.slide)
                }  else {
                Button(action:{
                    withAnimation{
                    self.showData = true
                    }
                    
                })
                {
                    // Creating Hstack for data and image
                    HStack{
                        // Text of button
                        Text("Data")
                            .font(.custom("Futura", size: 17))
                            .fontWeight(.ultraLight)
                        // Image of button
                        Image(systemName: "chart.pie")
                        
                    } //Hstack
                        .padding(.top, 180.0)
                        .padding(.bottom, 2)
                        .aspectRatio(contentMode: .fit)
                        .frame(minWidth: 0, maxWidth: 300)
                        .frame(minHeight: 0, maxHeight: 200)
                        .padding()
                        .background(RoundedRectangle(cornerRadius: 10).stroke(Color.blue, lineWidth: 2))
                        .padding(.bottom, 50)
                    //Data button settings
                } //data button
            }//showing data sheet
        

0 个答案:

没有答案