2

With the .edgesIgnoringSafeArea(.all) you can ignore all safe area, but is there also something like .none so you can switch between the two via something like .edgesIgnoringSafeArea(isFullscreen ? .all : .none)? Or how would you achieve this effect?

Mark
  • 16,906
  • 20
  • 84
  • 117

1 Answers1

3

Yes, this can be easily done. Here is some example code:

struct ContentView: View {

@State var isFullscreen = false

var body: some View {
    VStack {
        Spacer()
        Button(action: {
            self.isFullscreen.toggle()
        }) {
            Text("Fullscreen")
        }
    }
    .edgesIgnoringSafeArea(isFullscreen ? .all : .init()) // This is what you need.       
} }
Dharman
  • 30,962
  • 25
  • 85
  • 135
Kuhlemann
  • 3,066
  • 3
  • 14
  • 41
  • This doesn't seem to work as a "real" `.none` since it doesn't reverse `.edgesIgnoringSafeArea(:)` from superviews ... In this example it probably just says "ignore nothing" but not explicitly "ignore none and undo previeous ignores", which is what I am trying to achieve. Any Ideas? :) – smat88dd Oct 10 '20 at 04:44
  • This was helpful for me: https://stackoverflow.com/a/61432382/3078330 – smat88dd Oct 10 '20 at 04:53