1

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? I tried .present() .fullScreenCover() and still not working properly. 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()
            }
             
Scott
  • 51
  • 8

1 Answers1

1

You just nee to reorder your modifiers. Here is the solution provided it will work in 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.

 @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 ....
               .....
              .....
            }
Reed
  • 944
  • 7
  • 15
  • hey @Reed I am getting `Value of type 'Button' has no member 'fullScreenCover` – Scott Jul 11 '20 at 23:01
  • I just tested in Xcode 12 beta it works.. But, I will not be working on Xcode 12 beta, I want to work in Xcode 11, is there a workaround? – Scott Jul 11 '20 at 23:23
  • It is there but its tricky. Look at the answer I Posted here. https://stackoverflow.com/a/62767038 Look at the video I shared with the link there. Let me know if you are okay with something like that. we can achieve that in Xcode 11 and iso 13 – Reed Jul 12 '20 at 01:00
  • The image gif preview in that question seems the way I wanted which is in full screen. So, I guess I am okay doing something like that. – Scott Jul 12 '20 at 01:25
  • so, your code does not bring up the full `MainView` on screen it just bring on the bottom like a small scroll view of the MainView content – Scott Jul 14 '20 at 01:52
  • It depends what’s the frame of the main view it reacts to that. If your main view has a frame of full screen then it will do so. – Reed Jul 14 '20 at 01:53