Потянуть, чтобы освежить с WkwebviewIOS

Программируем под IOS
Ответить Пред. темаСлед. тема
Anonymous
 Потянуть, чтобы освежить с Wkwebview

Сообщение Anonymous »

Я пытаюсь добавить притяжение, чтобы освежить в Wkwebview. Где в этом коде я бы добавил что -то, что позволило бы мне вызвать притяжение, чтобы обновить? Я не нашел никаких жизнеспособных способов добавить его в свой код, чтобы вы не найдете никаких попыток, чем я выполнить это в коде ниже. Большинство ответов, которые я нашел, находятся в Objective-C или языке, не поддерживаемых моим проектом. < /P>

import UIKit
import WebKit

class CycleViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {

var webView: WKWebView!
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var progressView: UIProgressView!

override func loadView() {
super.loadView()
}

override func viewDidLoad() {
super.viewDidLoad()

progressView.setProgress(0.1, animated: true)

let webConfiguration = WKWebViewConfiguration()
webConfiguration.applicationNameForUserAgent = "Version/8.0.2 Safari/600.2.5"

let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0.0, height: self.containerView.frame.size.height))

webView = WKWebView(frame: customFrame, configuration: webConfiguration)
webView.uiDelegate = self
webView.navigationDelegate = self
self.containerView.addSubview(webView)
self.webView.translatesAutoresizingMaskIntoConstraints = false

self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .trailing, relatedBy: .equal, toItem: self.containerView, attribute: .trailing, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .leading, relatedBy: .equal, toItem: self.containerView, attribute: .leading, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .top, relatedBy: .equal, toItem: self.containerView, attribute: .top, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .bottom, relatedBy: .equal, toItem: self.containerView, attribute: .bottom, multiplier: 1, constant: 0))

progressView.sizeToFit()
progressView.progressTintColor = UIColor(red: 255/255, green: 204/255, blue: 0/255, alpha: 1.0)

webView.backgroundColor = UIColor.clear
webView.backgroundColor = UIColor(red: 0.0196, green: 0.4, blue: 0.2902, alpha: 1.0)
webView.isOpaque = false

self.webView.load(NSURLRequest(url: URL(string: "https://jwelsh19.wixsite.com/countryday")!) as URLRequest)

self.webView.addObserver(self, forKeyPath: "estimatedProgress", options: .new, context: nil)

}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
print(self.webView.estimatedProgress);
self.progressView.progress = Float(self.webView.estimatedProgress); }
}

@IBAction func home(_ sender: UIButton) {
let myURL = URL(string: "https://jwelsh19.wixsite.com/countryday")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}

@IBAction func refresh(_ sender: UIButton) {

webView.reload()

}

//This method will call when you press button.
@objc func acButtonPressed() {

print("button is pressed")
self.performSegue(withIdentifier: "Account", sender: self)
}
}
`


Подробнее здесь: https://stackoverflow.com/questions/532 ... -wkwebview
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «IOS»