Code Monkey home page Code Monkey logo

pulltorefreshkit's Introduction

PullToRefreshKit

Version Platform Language Swift Package Manager License

The example project contains some hot App refresh example.

Taobao YouKu QQ Video
Yahoo Weather Dian Ping QQ

Require

  • iOS 8
  • Swift 4+
  • XCode 10.2+

For Swift 3, See branch Swift3

Support

UITableView/UICollectionView/UIScrollView/UIWebView

  • Pull to refresh.
  • Pull/Tap to load more.
  • Pull left/right to load more(Currently only support chinese)
  • Elastic refresh
  • Easy to customize
  • English and Chinese

Install

CocoaPod

pod "PullToRefreshKit"

Carthage

github "LeoMobileDeveloper/PullToRefreshKit"

Swift Package Manager

.package(url: "https://github.com/LeoMobileDeveloper/PullToRefreshKit.git",  from: "0.8.9")

Useage

What is a container? A container is the object that hold the scrollView reference, most time it is a UIViewController object

Pull down to refresh

self.tableView.configRefreshHeader(container:self) { [weak self] in
    delay(2, closure: {
        self?.tableView.switchRefreshHeader(to: .normal(.success, 0.5))
    })
}

If you do not want any delay:

self.tableView.switchRefreshHeader(to: .normal(.none, 0.0))

Pull up to load more

Support three mode to fire refresh action

  • Tap
  • Scroll
  • Scroll and Tap
self.tableView.configRefreshFooter(container:self) { [weak self] in
	delay(1.5, closure: {
	    self?.tableView.switchRefreshFooter(to: .normal)
	})
};

Remove footer:

self.tableView.switchRefreshFooter(to: .removed)

No more Data

self.tableView.switchRefreshFooter(to: .noMoreData)

Pull left to exit

scrollView.configSideRefresh(with: DefaultRefreshLeft.left(), container:self, at: .left) {
   self.navigationController?.popViewController(animated: true)
};

Pull right to Pop

let right  = DefaultRefreshRight.right()
right.setText("👈滑动关闭", mode: .scrollToAction)
right.setText("松开关闭", mode: .releaseToAction)
right.textLabel.textColor = UIColor.orange
scrollView.configSideRefresh(with: right, container:self, at: .right) { [weak self] in
    self?.navigationController?.popViewController(animated: true)
};

Config the default refresh text

PullToRefershKit offer SetUp operator,for example

let header = DefaultRefreshHeader.header()
header.setText("Pull to refresh", mode: .pullToRefresh)
header.setText("Release to refresh", mode: .releaseToRefresh)
header.setText("Success", mode: .refreshSuccess)
header.setText("Refreshing...", mode: .refreshing)
header.setText("Failed", mode: .refreshFailure)
header.tintColor = UIColor.orange
header.imageRenderingWithTintColor = true
header.durationWhenHide = 0.4
self.tableView.configRefreshHeader(with: header,container:self) { [weak self] in
    delay(1.5, closure: {
        self?.models = (self?.models.map({_ in random100()}))!
        self?.tableView.reloadData()
        self?.tableView.switchRefreshHeader(to: .normal(.success, 0.3))
    })
};

Customize

You just need to write a UIView sub class,and make it conforms to these protocols

  • RefreshableHeader
  • RefreshableFooter
  • RefreshableLeftRight

For exmaple,to create a custom header

    //Height of the refresh header
    func heightForHeader()->CGFloat
    
    //Distance from top when in refreshing state
    func heightForRefreshingState()->CGFloat
   
    //Will enter refreshing state,change view state to refreshing in this function
    func didBeginrefreshingState()

    //The refreshing task is end.Refresh header will hide.Tell user the refreshing result here.
    func didBeginHideAnimation(result:RefreshResult)
    
    //Refresh header is hidden,reset all to inital state here
    func didCompleteHideAnimation(result:RefreshResult)
    
    //Distance to drag to fire refresh action ,default is heightForRefreshingState
    optional func heightForFireRefreshing()->CGFloat
    
    //Percent change during scrolling
    optional func percentUpdateDuringScrolling(percent:CGFloat)
    
    //Duration of header hide animation
    optional func durationOfHideAnimation()->Double
    

Author

Leo, [email protected]

License

PullToRefreshKit is available under the MIT license. See the LICENSE file for more info.

pulltorefreshkit's People

Contributors

leomobiledeveloper avatar pinguo-tanglei avatar stevapple avatar z415073783 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pulltorefreshkit's Issues

请教大神

请教大神,左滑 横向collectionview 刷新提示文字和图片 不在collectionview 高度的正中间 该怎么修复这个高度呢?
我在pulltorefresh 225行 设置height: self.frame.height / 2 但是并不能完美的居中 还是偏上
请问怎样能完美的解决呢?

footer

添加上拉刷新没添加成功

RefreshRightContainer deinit 重复移除Observers

RefreshRightContainer deinit 重复移除Observers PullToRefreshKitConst.KPathOffSet
项目源码:

  deinit{
       removeObservers()
   }
   // MARK: - Private -
   fileprivate func addObservers(){
       attachedScrollView?.addObserver(self, forKeyPath:PullToRefreshKitConst.KPathOffSet, options: [.old,.new], context: nil)
       attachedScrollView?.addObserver(self, forKeyPath:PullToRefreshKitConst.KPathContentSize, options:[.old,.new] , context: nil)
   }
   fileprivate func removeObservers(){
       attachedScrollView?.removeObserver(self, forKeyPath: PullToRefreshKitConst.KPathOffSet,context: nil)
       attachedScrollView?.removeObserver(self, forKeyPath: PullToRefreshKitConst.KPathOffSet,context: nil)
   }

Footer at top when empty data

Thank you for great work,

I have small issue if you could help me please?

simulator screen shot - iphone 8 - 2018-04-15 at 12 46 41

As you can see when number of items is ZERO ( empty ) ,, footer goes up at top

simulator screen shot - iphone 8 - 2018-04-15 at 12 48 05

Any idea how to keep it at bottom? ( like header at top )

首次下拉时header显示的是未修改前的pulltorefresh,请问如何修改?

已按照demo设置了header的文字,但是首次下拉不改变
xcode9.1,ios11.1,模拟器iphoneX
使用的是v0.8.8
望解答

lazy var header: DefaultRefreshHeader = {
let header = DefaultRefreshHeader.header()
header.setText("下拉刷新", mode: .pullToRefresh)
header.setText("释放刷新", mode: .releaseToRefresh)
header.setText("数据刷新成功", mode: .refreshSuccess)
header.setText("刷新中...", mode: .refreshing)
header.setText("数据刷新失败,请检查网络设置", mode: .refreshFailure)
header.tintColor = #colorLiteral(red: 0.9995891452, green: 0.6495086551, blue: 0.2688535452, alpha: 1)
header.imageRenderingWithTintColor = true
header.durationWhenHide = 0.4
return header
}()

SnapKit布局时无法在不拖动时刷新

    let tableView = UITableView(frame: .zero, style: .plain)
    view.addSubview(tableView)
    tableView.snp.makeConstraints { (make) in
        make.edges.equalToSuperview()
    }
    tableView.configRefreshHeader(container: self) {
        _ = delay(2, task: {})
    }
    tableView.switchRefreshHeader(to: .refreshing)

修改为frame布局时正常,snapkit布局时无法自动刷新而且拖拽也无法触发刷新

内存泄露

tableview 设置 RefreshableHeader 之后, 不会释放

更新

能否更新到swift4.2版本

刚发现一个ios13下的BUG,同样代码ios12没问题

image

UICollectionViewCell高度自适应,
用的是自定义cell 中的 preferredLayoutAttributesFitting 方法来返回每个cell的经计算后的不同高度
下拉刷新时,崩溃了, IOS12下是好的,也在项目中用了好久了

最小重现代码如下:
`import UIKit
import PullToRefreshKit

class TestViewController: UIViewController, UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var layout: UICollectionViewFlowLayout!

override func viewDidLoad() {
    super.viewDidLoad()
    layout.estimatedItemSize = CGSize(width: UIScreen.main.bounds.width, height: 0)
    collectionView.dataSource = self
    collectionView.register(MyCollectionViewCell.self, forCellWithReuseIdentifier: "cell")
    
    let refreshHeader = ElasticRefreshHeader()
    self.collectionView.configRefreshHeader(with: refreshHeader, container: self) { [weak self] in
        print("refreshHeader")
        self?.collectionView.switchRefreshHeader(to: .normal(.success, 0.5))
    }
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 100
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MyCollectionViewCell
    cell.backgroundColor = UIColor.red
    return cell
}

}

class MyCollectionViewCell: UICollectionViewCell {
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
var newFrame = layoutAttributes.frame
newFrame.size.height = 100 // 这里根据内容计算出每个cell的不同高度
layoutAttributes.frame = newFrame
return layoutAttributes
}
}`

CocoaPods installation hints:

CocoaPods installation hints:
Could not find remote branch 0.3.1 to clone. fatal: Remote branch 0.3.1 not found in upstream origin?

xcode9.3+swift4.1上出现大量这样的错误,但程序却能正常运行

Friend.storyboard: error: IB Designables: Failed to render and update auto layout status for FriendRequestViewController (WEa-Aa-6Nn): dlopen(PullToRefreshKit.framework, 1): no suitable image found. Did find:
PullToRefreshKit.framework: required code signature missing for 'PullToRefreshKit.framework'

没升级xcode前完全正常,现在看不懂了,完全找不到错误在哪,麻烦大神帮忙看看,谢谢。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.