简体   繁体   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?

I have an app were when I tap on a button to open a new view it shows my view because I am using.sheet(), is there a way to make the.sheet() full screen rather than mid way?我有一个应用程序,当我点击一个按钮打开一个新视图时,它会显示我的视图,因为我正在使用.sheet(),有没有办法让.sheet() 全屏而不是中途? I tried.present().fullScreenCover() and still not working properly.我试过.present().fullScreenCover() 仍然无法正常工作。 Can anyone help me solve this issue.谁能帮我解决这个问题。 thanks for the help.谢谢您的帮助。

@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()
            }
             

You just nee to reorder your modifiers.你只需要重新排序你的修饰符。 Here is the solution provided it will work in iOS 14 +这是提供它将在 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)

Here is the workaround approach for iOS 13.这是 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.

相关问题 如何在 SwiftUI 中全屏显示视图? - How to present a view full-screen in SwiftUI? 使用shouldPerformSegueWithIdentifier时,必须轻按两次按钮才能进入下一个视图 - Button must be tapped twice to go next view when using shouldPerformSegueWithIdentifier 如何在 SwiftUI 中以模态方式推送下一个屏幕 - How to Modally push next Screen to be full in SwiftUI 轻按时,iOS Animate表格视图单元会变为全屏 - iOS Animate table view cell into full screen when tapped SwiftUI 如何在点击按钮时推送到下一个屏幕 - SwiftUI How to push to next screen when tapping on Button 如何在动作表中呈现动作扩展而不是全屏模态视图? - How to present an action extension in an action sheet rather than full-screen modal view? 当我们点击图像时,如何以全屏方式缩放图像 - How to zoom the image along with full screen when we tapped on it 点击文本字段时如何显示视图控制器? - How to present a view controller when a text field is tapped? 在单元格中轻按imageview时如何转到其他视图 - How to go to other view when tapped imageview in a cell 如何从SwiftUI中的工作表视图go到另一页? - How to go to another page from a sheet view in SwiftUI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM