How to make a pop up view?

I am new to Xcode and I have made a small game in SwiftUI. I want to have a button in the corner that displays a new view with the some rules on it. I don’t want to use navigationView or Tabview because it takes up to much space from the game.

how do I achieve this? thank you already :)

There is a modifier called popup. You could add it to your button.

@State var presentPopup = false

Button { presentPopup = true } label: { Text("Rules") }
.popup(isPresented: $presentPopup) {
    TheViewWithTheRulesAndADismissButton()
}

Or something like that. Just be clear that on iPhone it will appear as a sheet, that means, using all the screen.

thanks for helping me.

I tried what u said but got an error on "var body: some View" that says "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions"

this is the code I wrote..

 Button { presentPopup = true } label: { Text("Rules") }

.popup(isPresented: $presentPopup) {

Text("test").frame(width: 100, height: 100, alignment: .center)                     }

I also wrote the State variable.

You should use the popover modifier. This will show a sheet on iPhone and an overlaying view on iPad.

Here’s an example:

Button("Rules") {
  presentPopup = true
}
.popover(isPresented: $presentPopup, arrowEdge: .bottom) {
  Text("test")
    .frame(width: 100, height: 100)
}


Check out the documentation for more information on usage.

How to make a pop up view?
 
 
Q