繁体   English   中英

如何在点击按钮时全屏显示.sheet() 以便将 go 显示到 SwiftUI 中的下一个视图?

[英]How to present .sheet() full screen when a button is tapped in order for it to go to the next view in SwiftUI?

我有一个应用程序,当我点击一个按钮打开一个新视图时,它会显示我的视图,因为我正在使用.sheet(),有没有办法让.sheet() 全屏而不是中途? 我试过.present().fullScreenCover() 仍然无法正常工作。 谁能帮我解决这个问题。 谢谢您的帮助。

@State var showingDetail = false
           Button(action: {
                withAnimation {
                    self.showingDetail.toggle()
                }
                 
                
            }) {
                Text("Enter")
                    .font(.headline)
                    .foregroundColor(.white)
                    .padding()
                    .frame(width: 300, height: 50)
                    .background(Color.accentColor)
                    .cornerRadius(15.0)
                    .shadow(radius: 10.0, x: 20, y: 10)
            }.padding(.top, 50).sheet(isPresented: $showingDetail) {
                
                MainView()
            }
             

你只需要重新排序你的修饰符。 这是提供它将在 iOS 14 + 中工作的解决方案

@State var showingDetail = false
           Button(action: {
                withAnimation {
                    self.showingDetail.toggle()
                }
                 
                
            }) {
                Text("Enter")
                    .font(.headline)
                    .foregroundColor(.white)
                    .padding()
                    .frame(width: 300, height: 50)
                    .background(Color.accentColor)
                    .cornerRadius(15.0)
                    .shadow(radius: 10.0, x: 20, y: 10)
            }.fullScreenCover(isPresented: $showingDetail) {
                
                MainView()
                  .edgesIngoringSafeArea(.all) // if you need to hide navigating and status bar
            }
             .padding(.top, 50)

这是 iOS 13 的解决方法。

 @State var showingDetail = false
 
             ZStack {

              if (!showingDetail) {
               Button(action: {
                    withAnimation {
                        self.showingDetail.toggle()
                    }
                     
                    
                }) {
                    Text("Enter")
                        .font(.headline)
                        .foregroundColor(.white)
                        .padding()
                        .frame(width: 300, height: 50)
                        .background(Color.accentColor)
                        .cornerRadius(15.0)
                        .shadow(radius: 10.0, x: 20, y: 10)
                }
                } else {
                  // in main view you need to give a button where value of showing detail changes to false
                  // so clicking on that button will poppet this view
                   MainView(back: $showingDetail) 
                  .edgesIngoringSafeArea(.all)
                  .transition(.move(.bottom))
                }

               }




           struct MainView: some View{
           @binding back: Bool
              var body ....
               .....
              .....
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM