{"id":15293667,"url":"https://github.com/summerhf/zhrefresh","last_synced_at":"2025-10-29T14:45:02.277Z","repository":{"id":56930580,"uuid":"131250918","full_name":"SummerHF/ZHRefresh","owner":"SummerHF","description":"刷新控件","archived":false,"fork":false,"pushed_at":"2018-07-09T07:59:26.000Z","size":846,"stargazers_count":22,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-05T19:48:56.357Z","etag":null,"topics":["refreshcontrol","swift4","uicollectionview","uiscrollview","uitableview"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SummerHF.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-27T05:46:22.000Z","updated_at":"2022-06-13T07:15:13.000Z","dependencies_parsed_at":"2022-08-21T05:50:18.969Z","dependency_job_id":null,"html_url":"https://github.com/SummerHF/ZHRefresh","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/SummerHF/ZHRefresh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SummerHF%2FZHRefresh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SummerHF%2FZHRefresh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SummerHF%2FZHRefresh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SummerHF%2FZHRefresh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SummerHF","download_url":"https://codeload.github.com/SummerHF/ZHRefresh/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SummerHF%2FZHRefresh/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279059700,"owners_count":26095012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-15T02:00:07.814Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["refreshcontrol","swift4","uicollectionview","uiscrollview","uitableview"],"created_at":"2024-09-30T16:50:28.173Z","updated_at":"2025-10-15T07:47:21.968Z","avatar_url":"https://github.com/SummerHF.png","language":"Swift","readme":"\u003ch1 align=\"center\"\u003eZHRefresh\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://cocoapods.org/pods/ZHRefresh\"\u003e\u003cimg src=\"https://img.shields.io/badge/swift-4.0-orange.svg?style=flat\"\u003e\u003c/a\u003e\n\u003ca href=\"https://twitter.com/DefinetelyLoser\"\u003e\u003cimg src=\"https://img.shields.io/badge/twitter-@SummerHF-blue.svg?style=flat\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cstrong\u003eSwift\u003c/strong\u003e版的刷新控件, \u003cstrong\u003eMJRefresh\u003c/strong\u003e的翻版\u003c/p\u003e\n\n## Contents\n\n\u003cstrong\u003eswift\u003c/strong\u003e版的下拉刷新框架, 一行代码搞定\u003cstrong\u003e上拉加载, 下拉刷新\u003c/strong\u003e\n\n* 开始使用\n\t* [Features 【支持哪些控件刷新】](#Features)\n\t* [Installation 【如何安装】](#Install)\n\t* [Class structure 【类结构】](#structure)\n\t\n* 常见API\n\t* [ZHRefreshComponent.swift](#ZHRefreshComponent.swift)\n\t* [ZHRefreshHeader.swift](#ZHRefreshHeader.swift)\n\t* [ZHRefreshFooter.swift](#ZHRefreshFooter.swift)\n\t* [ZHRefresh.swift](#ZHRefresh.swift)\n* 使用例子\n\t* [参考](#参考)\n\t* [下拉刷新(仿QQ阅读)](#the_drop_down_qq_reader)\n\t* [下拉刷新(默认)](#the_drop_down_default)\n\t* [下拉刷新(动画图片)](#the_drop_down_animate)\n\t* 由于demo较多, 就不一一截图了, 有需要的可以自行下载运行...\n\t\n----------\n\t\n### \u003ca id=\"Features\"\u003e\u003c/a\u003e支持哪些控件刷新\n继承自\u003cstrong\u003eUIScollView\u003c/strong\u003e的类都可以使用.如\n\u003cstrong\u003eUIScrollView\u003c/strong\u003e, \u003cstrong\u003eUITableView\u003c/strong\u003e, \u003cstrong\u003eUICollectionView\u003c/strong\u003e, \u003cstrong\u003eWKWebView\u003c/strong\u003e, \u003cstrong\u003eUIWebView\u003c/strong\u003e...\n\n### \u003ca id=\"Install\"\u003e\u003c/a\u003e如何安装\n* 使用CocoaPods安装\n\n因为该框架是基于\u003cstrong\u003eswift\u003c/strong\u003e的, 所以请确保打开\u003cstrong\u003euse_frameworks!\u003c/strong\u003e的注释, 允许使用动态库.\n\n```\npod 'ZHRefresh'\n```\n\n然后\n\n```\npod install\n```\n\n在需要使用该框架的地方\n\n```\nimport ZHRefresh\n```\n\n即可\n\n---------------\n\n### \u003ca id=\"structure\"\u003e\u003c/a\u003e类结构\n![类结构](https://ws4.sinaimg.cn/large/006tNc79gy1frb7sduotwj313u0b7q3b.jpg)\n\n\n## \u003ca id=\"ZHRefreshComponent.swift\"\u003e\u003c/a\u003eZHRefreshComponent.swift\n\n```swift\n    /// 正在刷新的回调\n    public var refreshingBlock: ZHRefreshComponentRefreshingBlock?\n    /// 开始刷新后的回调(进入刷新状态后的回调)\n    public var beginRefreshingCompletionBlock: ZHRefreshComponentbeiginRefreshingCompletionBlock?\n    /// 结束刷新的回调\n    public var endRefreshingCompletionBlock: ZHRefreshComponentEndRefreshingCompletionBlock?\n    /// 回调对象\n    public weak var refreshTarget: AnyObject?\n    /// 回调方法\n    public var refreshAction: Selector?\n    \n```\n\n## \u003ca id=\"ZHRefreshHeader.swift\"\u003e\u003c/a\u003eZHRefreshHeader.swift\n\n```swift\n    /// 类方法, 快速的创建下拉刷新控件\n    public static func headerWithRefresing(target: AnyObject, action: Selector) -\u003e ZHRefreshHeader\n    /// 类方法, 快速的创建带有正在刷新回调的下拉刷新控件\n    public static func headerWithRefreshing(block: @escaping ZHRefreshComponentRefreshingBlock) -\u003e ZHRefreshHeader\n    /// 忽略多少scrollView的contentInset的top\n    public var ignoredScrollViewContentInsetTop: CGFloat = 0.0\n    /// 上一次下拉刷新成功的时间\n    public var lastUpdatedTime: Date?\n```\n\n## \u003ca id=\"ZHRefreshFooter.swift\"\u003e\u003c/a\u003eZHRefreshFooter.swift\n\n```swift\n\t /// 带有回调target和action的footer\n    static public func footerWithRefreshing(target: AnyObject, action: Selector) -\u003e ZHRefreshFooter\n\t /// 类方法, 创建footer\n    static public func footerWithRefreshing(block: @escaping ZHRefreshComponentRefreshingBlock) -\u003e ZHRefreshFooter\n    /// 提示没有更多数据\n    public func endRefreshingWithNoMoreData()\n    /// 重置没有更多数据\n    public func resetNoMoreData()\n```\n\n## \u003ca id=\"ZHRefresh.swift\"\u003e\u003c/a\u003eZHRefresh.swift\n\n```swift\n   /// header and footer\n\tpublic extension UIScrollView {\n    /// header\n     @objc dynamic var header: ZHRefreshHeader? {\n        get {\n            return objc_getAssociatedObject(self, \u0026ZHRefreshKeys.header) as? ZHRefreshHeader\n        }\n        set {\n            if let newHeader = newValue {\n                if let oldHeader = header {\n                    /// 如果有旧值, 删除它\n                    oldHeader.removeFromSuperview()\n                }\n                /// 添加新的\n                self.insertSubview(newHeader, at: 0)\n                /// 存储新值\n                objc_setAssociatedObject(self, \u0026ZHRefreshKeys.header, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN)\n            }\n        }\n    }\n\n    /// footer\n     @objc dynamic var footer: ZHRefreshFooter? {\n        get {\n            return objc_getAssociatedObject(self, \u0026ZHRefreshKeys.footer) as? ZHRefreshFooter\n        }\n        set {\n            if let newFooter = newValue {\n                if let oldFooter = footer {\n                    /// 如果有旧值, 删除它\n                    oldFooter.removeFromSuperview()\n                }\n                /// 添加新值\n                self.insertSubview(newFooter, at: 0)\n                /// 存储新值\n                objc_setAssociatedObject(self, \u0026ZHRefreshKeys.footer, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN)\n            }\n        }\n    }\n}\n```\n\n## \u003ca id=\"参考\"\u003e\u003c/a\u003e参考\n请下载[源程序](https://github.com/SummerHF/ZHRefresh), 并打开附带的`demo`程序 `Example`-\u003e`ZHRefresh.xcworkspace`\n\n* `MainViewController.swift` 主入口\n* `CollectionViewController.swift` 提供`collectionView相关`的实例程序\n* `TableViewController.swift`提供`tableView相关`的实例程序\n* `WebViewController.swift`提供`webView相关`的实例程序\n* `Example.swift`提供模型数据\n\n具体结构如下图:\n![](https://ws2.sinaimg.cn/large/006tNc79gy1frb8qg100wj30960a10sy.jpg)\n\n\n以下截屏皆取自`iPhoneX`\n\n## \u003ca id=\"the_drop_down_qq_reader\"\u003e\u003c/a\u003e下拉刷新(仿QQ阅读)\n\ncode:\n```swift\n  // MARK: - 下拉刷新 默认样式\n\n     /// 添加刷新控件\n        self.tableView.header = ZHDIYQQReaderHeader.headerWithRefreshing { [weak self] in\n            guard let `self` = self else { return }\n            self.loadQQReaderNewData()\n        }\n        /// 开始刷新\n        self.tableView.header?.beginRefreshing()\n\t\n\t/// 结束刷新 \n        (self.tableView.header as? ZHDIYQQReaderHeader)?.endRefreshWith(success: true)\n```\nscreenShots:\n![](https://ws2.sinaimg.cn/large/006tKfTcgy1ft3nkwkx29g309f0kgq66.gif)\n\n\n## \u003ca id=\"the_drop_down_default\"\u003e\u003c/a\u003e下拉刷新(默认)\n\ncode:\n```swift\n  // MARK: - 下拉刷新 默认样式\n\n    @objc func action01() {\n        /// 设置回调, 一旦进入刷新状态 就会调用block\n        self.tableView.header = ZHRefreshNormalHeader.headerWithRefreshing { [weak self] in\n            guard let `self` = self else { return }\n            self.loadNewData()\n        }\n        /// 进入刷新状态\n        self.tableView.header?.beginRefreshing()\n    }\n```\nscreenShots:\n![](https://ws1.sinaimg.cn/large/006tNc79gy1frb9f0li9ng308k0ihgni.gif)\n\n## \u003ca id=\"the_drop_down_animate\"\u003e\u003c/a\u003e下拉刷新(动画图片)\n\ncode:\n```swift\n  // MARK: - 下拉刷新 动态图片\n\n    @objc func action02() {\n        /// 一旦进入刷新状态 就会调用target的action, 也就是调用self的loadNewData\n        self.tableView.header = ZHRefreshChiBaoZiHeader.headerWithRefresing(target: self, action: #selector(loadNewData))\n        self.tableView.header?.beginRefreshing()\n    }\n```\nscreenShots:\n![](https://ws1.sinaimg.cn/large/006tNc79gy1frb9fyem4mg308k0ihgog.gif)\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsummerhf%2Fzhrefresh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsummerhf%2Fzhrefresh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsummerhf%2Fzhrefresh/lists"}