Giter Site home page Giter Site logo

wxgbridgeq / swiftpulltorefresh Goto Github PK

View Code? Open in Web Editor NEW
463.0 8.0 55.0 3.23 MB

An easy way to implement pull-to-refresh feature based on UIScrollView extension, written in Swift 4.

License: MIT License

Ruby 2.34% Swift 96.23% Objective-C 1.43%
swift pull-to-refresh scrollview-compatible

swiftpulltorefresh's People

Contributors

b3ll avatar harriescc avatar jhonny-me avatar wxgbridgeq 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

swiftpulltorefresh's Issues

spr_endRefreshingWithNoMoreData这个方法用着无效果

你新添加的,去除上拉加载的就是spr_endRefreshingWithNoMoreData这个方法吧,我试过了,并不能去除上啦加载呀?

    self.tableView?.spr_setIndicatorFooter { [weak self] in
        DispatchQueue.main.asyncAfter(wallDeadline: .now() + 2, execute: {
            YJDebugPrint("上啦加载更多")
            self?.tableView?.spr_endRefreshing()
        })
    }
    self.tableView?.spr_endRefreshingWithNoMoreData()

就像这样,仅仅添加,然后马上删除,也还是有上拉加载

More than 1 scrollview

Here is the current situation:

I have 2 tabs, and each has a UITableView using SwiftPulltoRefresh. In my case I am using a custom header but int shouldn't matter. You will notice that on the second UITableView created the pull to refresh won't work. The animation still happens but the refresh completion handler is never called. Also sometimes the content insets and offset are not properly reset.

This is because every instance of a scrollview points to the same header.

In UIScrollView+Extensions.swift you define:

private var headerKey: UInt8 = 0

Every time you reference spr_header you call objc_getAssociatedObject with the exact same key.

My quick and dirty solution was to define headerKey as:

private var headerKey: UInt32 = 0

and in spr_setCustomHeader:

public func spr_setCustomHeader(_ header: RefreshView) {
headerKey = UInt32(arc4random())
self.spr_header = header
}

Now each scrollview has a unique key for each header and there are no more issues. You need to do this for footerKey and tempFooterKey as well.

Can't change indicator color

Loading indicator color cannot be changed ! I don't want custom header i just want to change the default color of loading indicator

left and right side

Would be nice to have left and right sided refresh, for example for UIPageviewcontroller

Crash when run on IOS 10.3.3

It works well on iOS 11.3, but failed on 10.3.3 with logs:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x19be2e10 of class UIScrollViewPanGestureRecognizer was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x19a8cef0> (
<NSKeyValueObservance 0x17f6c4d0: Observer: 0x17fa5550, Key path: state, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x17f60500>
<NSKeyValueObservance 0x19ab9180: Observer: 0x19a1d950, Key path: state, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x17f60500>
)'

I guess problem happen when you didn't remove observer in RefreshView.

Memory leaks

Class used RefreshView:

import SwiftPullToRefresh
import MaterialComponents


final class KZFooter: RefreshView {
    private var loader: MDCActivityIndicator!
    
    override public init(style: Style, height: CGFloat, action: @escaping () -> Void) {
        loader             = MDCActivityIndicator(frame: CGRect(x: 0, y: 0, width: 32, height: 32))
        loader.cycleColors = [UIColor.dcmBrightLightBlue]
        loader.radius      = 15
        
        super.init(style: style, height: height, action: action)
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override func didUpdateState(_ isRefreshing: Bool) {

        if isRefreshing {
            addSubview(loader)
            loader.center = CGPoint(x: frame.width / 2, y: frame.height / 2)
            loader.startAnimating()
        } else {
            loader.removeFromSuperview()
            loader.stopAnimating()
        }
    }
    
    override func didUpdateProgress(_ progress: CGFloat) {

    }
}

Where I use this class:

final class CurrentVC : UIViewController {
    var viewModel: CurrentVM!
    var footer: KZFooter!
    var header: KZFooter!
    @IBOutlet weak var table: UITableView!


    override func viewDidLoad() {
        super.viewDidLoad()

        footer = KZFooter(style: .autoFooter, height: 57) { [weak self] in
            guard let sself = self else { return }
            sself.viewModel!.loadNextPage.next(())
        }
        
        table.spr_setCustomFooter(footer)
        
        header = KZFooter(style: .header, height: 57) { [weak self] in
            guard let sself = self else { return }
            sself.viewModel!.refresh.next(())
        }

        table.spr_setCustomHeader(header)
	}
}

It don't deallocate and every time I reopen screen it create more instances of KZFooter

screen shot 2018-02-19 at 12 36 38 pm

screen shot 2018-02-19 at 12 49 02 pm

screen shot 2018-02-19 at 12 36 34 pm

Any ideas how to fix that

没有移除刷新控件的方法

在很多情况下,比如上啦加载更多,一开始有,后来全部数据加载完了,就要移除刷新控件,你少写了个移除方法(或者我看漏了哪个文件,没找到),可以添加一下嘛,谢谢啦😀

UITableView添加IndicatorFooter后, Row点击事件不响应

scrollView.spr_addIndicatorFooter { [weak self] in // do your action here // self?.scrollView.spr_endRefreshing() }

我使用spr_addIndicatorFooter给UITableView添加了一个上拉加载控件,但是点击cell时 didSelectRowAt 不再响应?我把添加IndicatorFooter相关代码注释后一切正常,请问是bug,还是我代码问题?

swift4.0使用报错

ScrollViewExtension.swift里的结构体Default报错
Struct 'Default' is internal and cannot be referenced from a default argument value

请问一下,在 collectionView 中使用为什么会有诡异的动画?

我在 UICollectionViewController 中分别注册了 Cell 和 UICollectionElementKindSectionHeader:

self.collectionView!.register(WNHomeCollectionViewCell.self, forCellWithReuseIdentifier: cellReuseIdentifier)
        self.collectionView?.register(WNHomeCollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: sectionHeaderReuseIdentifier)

当我尝试成功加载到数据刷新 collectionView 的时候(直接 reloadData),这个 SectionHeader 会有一个很诡异的动画,如下图:

collectionView?.spr_setIndicatorHeader(action: { [weak self] in
            self?.goodViewModel.getGoodList(goodParameter: WNGoodParameter(), onSuccess: { 
                self?.collectionView?.reloadData()
            }, onFailure: { (_) in
            }, completion: {
                self?.collectionView?.spr_endRefreshing()
            })
        })

Load more on ipad not working

Hi,
While using swiftpulltorefresh on ipad i figure out that when the content size is less the the height of scrollview the load more is not calling

Problem getting contentInset from RefreshView.

In the case of the contentInsetTop and contentInsetBottom variables of RefreshView, the value of contentInset and the value of adjustedContentInset are added.

However, this results in the same result as multiplying contentInset twice.
Because the value of adjustedContentInset is contentInset plus the value of safeArea.

The following fixes the problem where the scroll view is strange after refreshing or the value of contentOffset that is necessary for refreshing is too large:

private extension UIScrollView {
    var contentInsetTop: CGFloat {
        if #available(iOS 11.0, *) {
            return adjustedContentInset.top
        } else {
            return contentInset.top
        }

        return contentInset.top
    }

    var contentInsetBottom: CGFloat {
        if #available(iOS 11.0, *) {
            return adjustedContentInset.bottom
        } else {
            return contentInset.bottom
        }
    }
}

Changes in v2.4.5 broke indicator views when switching between tabs

Hello!

Latest commit broke indicator views when switching between tabs, see here:

Sample project can be downloaded here.

Reverting to v2.4.4 works fine.
I think the issue is that in v2.4.5 you moved the code to update tokens in RefreshView.swift from func willMove(toWindow newWindow: UIWindow?) to func willMove(toSuperview newSuperview: UIView?), but the latter isn't called when switching between tabs, so indicators are not updated properly.

A possible solution is to call the same code in both functions, but there should be a better one.

Thanks for your help!

Cannot pull down to refresh unless the scrollable area height is bigger than the device height

Thanks for the pod; works like a charm!

Have a slight issue though. The pull down to refresh is working great if the scrollView is actually scrollable; meaning that its content height is bigger than the device height. However; if the scrollView is not scrollable because its content's height is not bigger than the device height; I cannot pull down to refresh. To better illustrate; I am adding 2 videos to show my issue.

What can I do to enable pull to refresh in the second case?

First Vid:
Scrollview is scrollable because its content height is bigger than device height. Pull to refresh working:
https://www.dropbox.com/s/8svkh5ntag5znfo/vid1.mov?dl=0

Second Vid:
Scrollview is not scrollable because its content height is smaller than device height. Pull to refresh is not working:
https://www.dropbox.com/s/v80yk4s1c0fsg2a/vid2.mov?dl=0

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.