I have serious problem. My Xcode version is 13, iOS version is 15.
import SwiftUI
struct ContentView: View {
@State var isGo: Bool = false
var body: some View {
ZStack {
Button(action: {
self.isGo = true
}, label: {
Text("Go EmptyView")
})
EmptyView()
.background(Color.green)
.frame(width: 100, height: 100)
.sheet(isPresented: $isGo, onDismiss: nil, content: {
PopupView()
})
}
}
}
struct PopupView: View {
var body: some View {
Rectangle()
.fill(Color.green)
}
}
Above code is not working. But, Previous Xcode version or Previous iOS version is that code is working. Is that iOS bug? Is there anything solution?
3
Answers
You’re very close, not sure why nobody has offered help. Your code does work but in theory isn’t correct, you needed to move the where you called
.sheet
to outside yourZStack
and it works. But here’s a better approach without all the useless code.Finally in a last version you can use several sheets directly for main view and it works. You don’t need to create separate EmptyView() with sheet
Replace "EmptyView()" with "Spacer().frame(height:0)" did work for me on iOS15 and iOS14