2017-08-23 29 views
0

我正在我的iOS应用程序中使用swift实现JavaScript函数,它的工作。但是网页视图大小由导航栏覆盖。在实现Javascript之前,Web视图的大小是正确的。如何解决它?斯威夫特 - 实施Javascript后的导航栏覆盖Webview

我对这个函数参考: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

回答

0

我在viewDidLoad中

self.edgesForExtendedLayout = [] 
添加该代码解决我的问题