我有一个进度视图,可以跟踪通过WKWebView加载Youtube视频的状态。当它被加载时,我想要关闭progressView,因为当我点击我的应用程序的主页面时,状态栏仍然存在(但它不显示任何内容并占用空间,阻止我的应用程序的其他元素)。当完全加载progressView时,如何关闭progressView?
这是我的类,它处理WKWebView。
[AllowAnonymous]
[HttpGet("ExportExcel")]
public async Task<IActionResult> ExportExcel(int activos = 1, int idarticulo = -1, string filtro = "", string ordenar = "", int ordenarsentido = 1)
{
var memory = new MemoryStream();
var newFile = @"Export/Articulos.xlsx";
//IArticulosService articulosService = new ArticulosService(_validation.sConnectionString, _validation.sEmpresa);
var mycon = _validation.GetConnectionStringFromClientID("ClientId1");
IArticulosService articulosService = new ArticulosService(mycon, "Ciatema");
try
{
// Genero el excel con el listado
articulosService.ExportarExcel(newFile, activos, filtro, ordenar, ordenarsentido);
using (var stream = new FileStream(newFile, FileMode.Open))
{
await stream.CopyToAsync(memory);
}
memory.Position = 0;
return File(memory, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", newFile);
}
catch (QueryFormatException ex)
{
return BadRequest(ex.Message);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
如果您需要更多信息/更多代码,请与我们联系。
答案 0 :(得分:0)
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
guard let keyPath = keyPath else { return }
switch keyPath {
case "estimatedProgress":
// If you are using a `UIProgressView`, this is how you update the progress
progressView.isHidden = webView.estimatedProgress == 1
progressView.progress = Float(webView.estimatedProgress)
default:
break
}
}
并且不要忘记对观察者进行取消初始化
deinit {
//remove all observers
webView.removeObserver(self, forKeyPath: "estimatedProgress")
}
答案 1 :(得分:0)
检查WKNavigationDelegate
答案 2 :(得分:0)
您必须设置可输入:
public typealias isCompletion = (_ isCompleted: Bool?) -> Void
在课堂上添加如下变量:
var completion: isCompletion?
现在你必须创建一个方法:
func webViewLoad(_ iscompleted:@escaping isCompletion){
completion = iscompleted
let url = URL(string: videoURL)!
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
}
您必须在委托方法中设置完成
func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
print("finish to load")
completion(true)
}
您可以从viewdidload中调用此方法,如下所示:
// show loading from here
webViewLoad { (flag) in
//hide loading here
}