0

I am currently doing a project to convert website to ios application and successfully created it. The only problem is that the application can be zoom in and out. One more thing, whenever any form is click, the form will be zoomed. I am new to xcode (1 week of knowledge) pls guide me. Thanks!

Below is my current code.

WebView.swift

import SwiftUI
import WebKit
import UIKit

class ViewController: UIViewController{
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

struct SwiftUIWebView: UIViewRepresentable {
    
    let url: URL?
    
    func makeUIView(context: Context) -> WKWebView {
        let prefs =  WKWebpagePreferences()
        prefs.allowsContentJavaScript = true
        let config = WKWebViewConfiguration()
        config.defaultWebpagePreferences = prefs
        return WKWebView(
            frame: .zero,
            configuration: config
        )
    }
    
    func updateUIView(_ uiView: WKWebView, context: Context) {
        guard let myURL = url else {
            return
        }
        let request = URLRequest (url: myURL)
        uiView.load(request)
    }
}

ContentView.swift

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView{
            SwiftUIWebView(url: URL(string: "THE URL"))
                .navigationTitle("NAVIGATION NAME")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Haziq
  • 1
  • 4
  • Does this answer your question? [Disable zoom in WKWebView?](https://stackoverflow.com/questions/40452034/disable-zoom-in-wkwebview) – Andrew Apr 26 '21 at 10:18
  • try it. https://stackoverflow.com/a/66502026/11840031 change "yourWebView.scrollView.delegate = self" – Ten Apr 26 '21 at 10:26
  • Do i put the code at the ContentView.swift or WebView.swift – Haziq Apr 28 '21 at 03:07

0 Answers0