我想从mySubView中点击返回按钮。我有带按钮的付款ViewController,此按钮使view.addSubview(WkWebView)。因此,我可以打开WkWebView,但我无法丢失它。
我的代码:
self.automaticallyAdjustsScrollViewInsets = false
self.wkWebView.translatesAutoresizingMaskIntoConstraints = false
self.wkWebView.frame = CGRect.init(x: 0, y: 0, width: self.wkWebView.frame.size.width, height: self.wkWebView.frame.size.height)
self.view.addSubview(wkWebView)
loadUrl()
func loadUrl(){
let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = true
let myURL = URL(string: "https://ecg.test.upc.ua/go/enter")
var myRequest = URLRequest(url: myURL!)
myRequest.httpMethod = "POST"
wkWebView.load(myRequest)
}
答案 0 :(得分:0)
您可以尝试
let back = UIButton(type: .system)
back.frame = CGRect(x: 10, y: 20, width: 100, height: 50)
back.setTitle("Back", for: .normal)
back.sizeToFit()
back.addTarget(self, action: #selector(self.back), for: .touchUpInside)
wkWebView.addSubview(back)
//
@objc func back() {
wkWebView.removeFromSuperview()
}
//
还为与SuperView相关的wkWebView
提供了一个框架,并且不要在添加约束时设置self.wkWebView.translatesAutoresizingMaskIntoConstraints = false
self.wkWebView.frame = self.view.framw