Search code examples
swiftswiftuiswift3

SwiftUI Webview fullscreen issue


I'm trying to make WebView fit on screen But I couldn't I've tried that way.

import SwiftUI

extension View {
    func toAnyView() -> AnyView{
        AnyView(self)
    }
}

struct ContentView: View {

    @State private var showLoding: Bool = false
    @State private var scrollViewContentOffset: CGFloat = .zero
    var body: some View {
            ZStack{
                WebView(url: URL(string: "http://localhost:3000")!, showLoding: $showLoding)
                    .overlay(showLoding ? ProgressView("Loding...").toAnyView(): EmptyView().toAnyView())
                    .ignoresSafeArea()
                    .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

But that was the result.I couldn't make the stack goes up under the status bar.

Photo


Solution

  • Try using ".ignoresSafeArea()" after frame

    .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
    .ignoresSafeArea()