SwiftUI:how to get the secondView showed in full screen when I transfer to secondView from firstView

SwiftUI:

I am trying to transfer to secondView from firstView on iPad Pro(11inch) Horizontal screen,the secondView can not be showed in full screen

here is my code:


import SwiftUI


struct ContentView: View {

@State var showsecondView: Bool = false

var body: some View {

Button(action: {

self.showsecondView.toggle()

}) {

Text("firstView")

}.sheet(isPresented: self.$showsecondView){

secondView(showsecondView: self.$showsecondView)

}

}

}


struct ContentView_Previews: PreviewProvider {

static var previews: some View {

ContentView()

}

}

struct secondView: View {

@Binding var showsecondView: Bool

var body: some View {

Text("secondView")

}

}

Answered by OOPer in 401807022

You should better choose the right topic area: SwiftUI


`sheet` does not seem to provide much option to customize the presented view.


One way to present a view in full screen, is to declare the second view inside the first view, overlapping.


Try something like this:

import SwiftUI
struct ContentView: View {
@State var showsecondView: Bool = false
var body: some View {
ZStack {
Button(action: {
self.showsecondView.toggle()
}) {
Text("firstView")
}
if self.showsecondView {
SecondView(showsecondView: self.$showsecondView)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.red)
.animation(.easeInOut)
.transition(.move(edge: .bottom))
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct SecondView: View {
@Binding var showsecondView: Bool
var body: some View {
VStack {
Button(action: {
self.showsecondView = false
}) {
Text("dismiss")
}
Text("secondView")
}
}
}
Accepted Answer

You should better choose the right topic area: SwiftUI


`sheet` does not seem to provide much option to customize the presented view.


One way to present a view in full screen, is to declare the second view inside the first view, overlapping.


Try something like this:

import SwiftUI
struct ContentView: View {
@State var showsecondView: Bool = false
var body: some View {
ZStack {
Button(action: {
self.showsecondView.toggle()
}) {
Text("firstView")
}
if self.showsecondView {
SecondView(showsecondView: self.$showsecondView)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.red)
.animation(.easeInOut)
.transition(.move(edge: .bottom))
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct SecondView: View {
@Binding var showsecondView: Bool
var body: some View {
VStack {
Button(action: {
self.showsecondView = false
}) {
Text("dismiss")
}
Text("secondView")
}
}
}

thank you for your code ,it worked!

I want to ask another question: I transfered the view from the FirstView to SecondView, from SecondView to ThirdView.How to transferthe view from ThirdView to FirstView?

here is my code:

import SwiftUI
struct ContentView: View {
@State var showSecondView:Bool = false
var body: some View {
ZStack{
Button(action: {
self.showSecondView.toggle()
}) {
Text("showSecondView")
}
if self.showSecondView {
SecondView(showSecondView: self.$showSecondView)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.red)
.animation(.easeInOut)
.transition(.move(edge: .bottom))
}
}
}
}
struct SecondView: View {
@Binding var showSecondView:Bool
@State var showThirdView:Bool = false
var body: some View {
ZStack{
Button(action: {
self.showThirdView.toggle()
}) {
Text("showThirdView")
}
if self.showThirdView {
ThirdView(showThirdView: self.$showThirdView)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.yellow)
.animation(.easeInOut)
.transition(.move(edge: .bottom))
}
}
}
}
struct ThirdView: View {
@Binding var showThirdView:Bool
var body: some View {
ZStack{
Button(action: {
}) {
Text("showFirstView")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

How to transferthe view from ThirdView to FirstView?

Even in a classic environment using UIKit, such transition will make an infinite loop, and causes infinite memory consumption.


App does not manage views like web browser, go-only transitions will corrupt eventually.

Better find a way to return to the FirstView.

SwiftUI:how to get the secondView showed in full screen when I transfer to secondView from firstView
 
 
Q