Reputation: 51
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()
}
Upvotes: 1
Views: 2101
Reputation: 1002
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 ....
.....
.....
}
Upvotes: 1