拉动以刷新在iOS WebView中不起作用 [英] Pull to refresh not working in iOS WebView

查看:107
本文介绍了拉动以刷新在iOS WebView中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS中实现了直接 WKWebView

I've implemented a straight forward WKWebView in iOS.

   var refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: Selector("refreshWebView"), forControlEvents: UIControlEvents.ValueChanged)

这是 viewDidLoad()

以及相应的 refreshWebView 功能。但是当我在移动设备或模拟器上运行它时,无论我拖动多少,都没有拉动刷新动作。什么都没有被触发,几乎感觉我被困在屏幕的上限。哪里可能出错?

And the corresponding refreshWebView function. But when I run it on mobile or simulator, no matter how much I drag, there is no pull to refresh action. Nothing is triggered, and it almost feels like I am stuck to the upper bounds of the screen. Where can be going wrong?

推荐答案

尝试改变你的代码,如果你想拉到刷新 webView 您需要 addSubView UIRefreshControl 对象在 ScrollView 中的 webView 就像这样

Try to change your code like this, If you want to pull to refresh the webView you need to addSubView UIRefreshControl object in the ScrollView of webView like this

let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(self.refreshWebView(_:)), forControlEvents: UIControlEvents.ValueChanged)
webView.scrollView.addSubview(refreshControl)

像这样添加func

func refreshWebView(sender: UIRefreshControl) {
    print("refersh")
    webView.loadRequest(NSURLRequest(URL: NSURL(string: "https://google.com")!))
    sender.endRefreshing()
}

希望这对你有帮助。

这篇关于拉动以刷新在iOS WebView中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆