@available(iOS 10.0, *)
open var refreshControl: UIRefreshControl?
class ViewController: UIViewController {
var scrollView: UIScrollView?
override func viewDidLoad() {
super.viewDidLoad()
// 创建UIScrollView
let scrollView = UIScrollView(frame: UIScreen.main.bounds)
// 初始化UIScrollView
let v = UIView(frame: CGRect(x: 0, y: 0, width: scrollView.frame.width, height: 700))
v.backgroundColor = UIColor.purple
scrollView.addSubview(v)
scrollView.contentSize = v.frame.size
self.view.addSubview(scrollView)
self.scrollView = scrollView
// 创建UIRefreshControl
let refreshControl = UIRefreshControl()
scrollView.refreshControl = refreshControl
refreshControl.addTarget(self, action: #selector(refresh), for: UIControlEvents.valueChanged)
// 将UIRefreshControl添加到UIScrollView上
scrollView.refreshControl = refreshControl
}
func refresh() {
print("刷新事件执行了")
// 2秒后结束刷新
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) {
self.scrollView?.refreshControl?.endRefreshing()
}
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。