gpt4 book ai didi

Swift - Webview 在实现 Javascript 后被导航栏覆盖

转载 作者:行者123 更新时间:2023-11-28 15:21:58 24 4
gpt4 key购买 nike

我正在使用 swift 在我的 iOS 应用程序中实现 JavaScript 函数,并且成功了。但网页 View 大小被导航栏覆盖。在我实现 Javascript 之前,Web View 大小是正确的。如何解决?

我对此功能的引用:https://kinderas.com/technology/2014/6/15/wkwebview-and-javascript-in-ios-8-using-swift

@IBOutlet var containerView: UIView!

var availabilityWebview: WKWebView?
override func loadView() {
super.loadView()

let contentController = WKUserContentController();
let userScript = WKUserScript(
source: "redHeader()",
injectionTime: WKUserScriptInjectionTime.atDocumentEnd,
forMainFrameOnly: true
)
contentController.addUserScript(userScript)
contentController.add(
self,
name: "callbackHandler"
)

let config = WKWebViewConfiguration()
config.userContentController = contentController

//something wrong here
self.availabilityWebview = WKWebView(
frame: self.containerView.bounds,
configuration: config
)
self.view = self.availabilityWebview!
}

覆盖 func viewWillAppear

let url = URL(string: "http://ec2-52-221-231-3.ap-southeast-1.compute.amazonaws.com/gv/available-schedule_3.php?id=\(crewID)")
self.availabilityWebview?.load(URLRequest(url:url!))

App Screenshot

最佳答案

我通过在 viewDidLoad 中添加这段代码解决了我的问题

self.edgesForExtendedLayout = []

关于Swift - Webview 在实现 Javascript 后被导航栏覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45830754/

24 4 0