UIRefreshControl UIKit (SwiftUI 中文文档手册)

UIRefreshControl

一个标准控件,可以启动刷新滚动视图的内容。

class UIRefreshControl : UIControl

总览
一个标准的控制,你连接到任何对象,包括表视图和收集意见。将此控件添加到可滚动视图中,可为您的用户提供一种刷新其内容的标准方法。当用户向下拖动可滚动内容区域的顶部时,滚动视图将显示刷新控件,开始为其进度指示器设置动画,并通知您的应用。您可以使用该通知来更新您的内容并关闭刷新控件。

image.png

刷新控件可让您知道何时使用的target-action机制更新内容UIControl。激活后,刷新控件将调用您在配置时提供的操作方法。添加动作方法时,将其配置为侦听事件,如以下示例代码所示。使用操作方法来更新内容,并在完成后调用刷新控件的方法。

func configureRefreshControl () {
   // Add the refresh control to your UIScrollView object.
   myScrollingView.refreshControl = UIRefreshControl()
   myScrollingView.refreshControl?.addTarget(self, action:
                                      #selector(handleRefreshControl),
                                      for: .valueChanged)
}
    
@objc func handleRefreshControl() {
   // Update your content…

   // Dismiss the refresh control.
   DispatchQueue.main.async {
      self.myScrollingView.refreshControl?.endRefreshing()
   }
}

注意,UITableViewController还包括用于管理其关联表的刷新行为的属性。refreshControl

加入我们一起学习SwiftUI

QQ:3365059189
SwiftUI技术交流QQ群:518696470

猜你喜欢

转载自blog.csdn.net/iCloudEnd/article/details/108610901