我正在使用swift在我的iOS应用程序中实现JavaScript功能,并且它有效。但Web视图大小由导航栏覆盖。在我实现Javascript之前,Web视图大小是正确的。如何解决?
我对此功能的参考: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!))
答案 0 :(得分:0)
我通过在viewDidLoad
中添加此代码解决了我的问题self.edgesForExtendedLayout = []