ios – WebView camera preview does not fill preview frame


I have a webpage with a camera preview frame and a capture button.
But the preview feed does not take the entire preview frame. Marked the preview feed in red in the attached image.
If I rotate the phone to landscape, it appears correctly from then in landscape and portrait both.

Here goes my WebView:

struct MyWebView: UIViewRepresentable {

    let urlString: String?

    public let result : ((Result) -> Void)

    func makeUIView(context: Context) -> WKWebView {
        let config = WKWebViewConfiguration()
        config.userContentController = WKUserContentController()
        config.allowsInlineMediaPlayback = true

        if #available(iOS 9.0, *) {
            config.requiresUserActionForMediaPlayback = false
        } else {
            config.mediaPlaybackRequiresUserAction = false
        }

        // Set user controller
        let webView = WKWebView(frame: .zero, configuration: config)
        config.userContentController.add(MyWebViewHandler(result: result), name: "WebViewMessageHandler")
        
        return webView
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
        guard let url = urlString else {
            debugPrint("URL is empty")
            return
        }
        uiView.load(url)
    }

}

enter image description here

How can I ensure that the camera preview covers the full area specified for it?

Any insights or suggestions would be greatly appreciated. Thank you!

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img