func loadWebKit() {
let screenWidth:CGFloat = view.frame.size.width
let screenHeight:CGFloat = view.frame.size.height
// iPhone X , X以外は0となる
if #available(iOS 11.0, *) {
let window = UIApplication.shared.keyWindow
topPadding = window!.safeAreaInsets.top
}
//self.wkWebView.frame = CGRect(x: 0, y:topPadding, width:screenWidth, height:screenHeight*0.6)
self.wkWebView.frame = CGRect(x:-50, y:topPadding, width:screenWidth, height:screenHeight*0.6)
//wkWebView.frame = view.frame
wkWebView.navigationDelegate = self
wkWebView.uiDelegate = self
// スワイプでの「戻る・すすむ」を有効にする
wkWebView.allowsBackForwardNavigationGestures = true
//読み込むURL
let str: String = "https://taiwan-travel.net"
str = str.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)!
if let url = URL(string: str) {
let request = URLRequest(url: url)
wkWebView.load(request)
}
view.addSubview(wkWebView)
//念のためにviewの更新をする
view.setNeedsLayout()
//隠すこともできます//表示はfalse
wkWebView.isHidden = true
}
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
print("遷移開始")
}
もっと見る