Swift 4 从子视图返回
Swift 4 back from Subview
我想从 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)
}
你可以试试这个
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()
}
//
还为 wkWebView
提供了一个与 superView 相关的框架,并且不要像添加约束时那样设置 self.wkWebView.translatesAutoresizingMaskIntoConstraints = false
self.wkWebView.frame = self.view.framw
我想从 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)
}
你可以试试这个
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()
}
//
还为 wkWebView
提供了一个与 superView 相关的框架,并且不要像添加约束时那样设置 self.wkWebView.translatesAutoresizingMaskIntoConstraints = false
self.wkWebView.frame = self.view.framw