Giter Club home page Giter Club logo

ccbottomrefreshcontrol's Introduction

CCBottomRefreshControl

Category for UIScrollView class, that adds bottomRefreshControl property, that could be assigned to UIRefreshControl class instance. It implements an ability to add native iOS bottom pull-up to refresh control to UITableView or UICollectionView. Perfectly works with top top refresh control (see example project). Very useful for refreshing table and collection views that contain most recent items at the bottom. For example in chats.

Installation

CocoaPods is the recommended way to add CCBottomRefreshControl to your project.

Here's an example podfile that installs CCBottomRefreshControl.

Podfile

platform :ios, '7.0'

pod 'CCBottomRefreshControl'

Usage

Create an ordinary UIRefreshControl class instance, and assign additional UITableView/UICollectionView property bottomRefreshControl to it.

Additional triggerVerticalOffset property in UIRefreshControl class allows you to specify a vertical offset, after reaching which refresh will be triggered. Default value is 120.

#import <CCBottomRefreshControl/UIScrollView+BottomRefreshControl.h>

...

UIRefreshControl *refreshControl = [UIRefreshControl new];
refreshControl.triggerVerticalOffset = 100.;
[refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
self.tableView.bottomRefreshControl = refreshControl;

- (void)refresh {
    // Do refresh stuff here
}

License

CCBottomRefreshControl is released under the MIT license. See LICENSE

ccbottomrefreshcontrol's People

Contributors

filmhomage avatar jay18001 avatar kevindelord avatar manuege avatar markrickert avatar skyline75489 avatar vlasov 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

ccbottomrefreshcontrol's Issues

BottomRefreshControl layer zPosition results in appearance of refresh indicator on top of tableview

I have setup a bottomRefreshControl using the following code:

UIRefreshControl *refreshControl = [UIRefreshControl new];
 [refreshControl addTarget:self action:@selector(refresh)          
forControlEvents:UIControlEventValueChanged];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
 self.tableView.bottomRefreshControl = bottomRefreshControl;

When a user drags the tableView in the upwards direction, the bottomRefreshControl fades into place on top of the tableView rows that are being dragged upwards. This behavior differs from how the normal UIRefreshControl works; a UIRefreshControl on the top of a UITableView usually appears from beneath the tableView as a user drags the tableView downwards.

I was able to achieve this desired behavior by making a change to the following code to UIScrollView+BottomRefreshControl.m:

...
- (void)setBottomRefreshControl:(UIRefreshControl *)refreshControl {

    if (!self.context) {

        self.context = [CategoryContext new];

        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        tableView.userInteractionEnabled = NO;
        tableView.backgroundColor = [UIColor clearColor];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.transform = CGAffineTransformMakeRotation(M_PI);
        [tableView addSubview:refreshControl];
        tableView.layer.zPosition = -100; // CHANGE ADDED HERE...
        self.context.fakeTableView = tableView;

By adding a negative zPosition to the fakeTableView layer, the bottomRefreshControl appears from beneath the tableView as a user drags upwards.

The value of the zPosition can be any negative number, since the default value for layer zPosition's is 0.

Protect Method Swizzling from being executed more than once

I had an issue with CCBottomRefreshControl when running in a test target, where the swizzled method gets called in an endless loop. Further investigation showed that load was called two times with my test target only.

Ultimately, the issue for that was a different one, but nonetheless, the swizzling in the load methods should get protection from being called multiple times.

Please wrap the swizzling in every load in a
static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{

Also, consider using JRSwizzle (probably no one should ever re-implement swizzling on their own).

Activity Indicator only appears on top of CollectionView

I've followed your usage guide and it is working properly in terms of registering the pull up with the triggerHeight, what isn't working is the activity indicator is only appearing at the top of the view. Is there a way to control that?

Error with iOS 7.1

[!] The platform of the target Pods (iOS 7.1) is not compatible with ReactiveCocoa (3.0.0-alpha.1) which has a minimum requirement of iOS 8.0 - OS X 10.9.

I have commit that fixed this issue.
Change CCBottomRefreshControl.podspec as followed:

  • s.dependency 'ReactiveCocoa'
  • s.dependency 'ReactiveCocoa', '<= 2.0.0'

BottomRefreshControl attributedTitle is transposed across x axis (upside down and aligned on the top)

I have a a bottomRefreshControl setup as follows:

UIRefreshControl *refreshControl = [UIRefreshControl new];
 [refreshControl addTarget:self action:@selector(refresh)          
forControlEvents:UIControlEventValueChanged];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
 self.tableView.bottomRefreshControl = bottomRefreshControl;

The text "Pull to Refresh" is rotation 180 degrees and is also position on the top side of the refresh indicator.

When the following line is added, the problem is sort of fixed (the attributedTitle is correctly positioned, but the refresh indicator is now upside down):

refreshControl.transform = CGAffineTransformMakeRotation(M_PI);

One potentially extreme hack that fixes this is to add a second transformation to the above code, that will apply a second transformation to the refreshControl subview that contains the refresh indicator, as follows:

    refreshControl.transform = CGAffineTransformMakeRotation(M_PI);
    UIView *bottomRefreshControlIndicator = [[[refreshControl.subviews firstObject] subviews] firstObject];
    bottomRefreshControlIndicator.transform = CGAffineTransformMakeRotation(M_PI);

This will fix the position and orientation of the refreshControl's attributedTitle, keep it's positioning correct relative to the table view, and keep the indicator in the appropriate orientation.

I don't recommend using the above code, however, unless it is known for certain that the UIRefreshControl view won't be changing anytime. There is probably also a better way of searching through the UIRefreshControl's subviews. The above code was just my first attempt at figuring out what the inside's of UIRefreshControl looked like.

hide bottomRefreshControl

hi.
I very like CCBottomRefreshControl.
But I have bug, where I make self.tableBiew.bottomRefreshControl = nil; and next to set self.tableBiew.bottomRefreshControl = refresh;
faceTableView doesn't remove from SuperView.

I added code belof self.tableBiew.bottomRefreshControl = refresh;.
self.tableView.contentInset = UIEdgeInsetsZero;
self.tableView.scrollIndicatorInsets = UIEdgeInsetsZero;

need self.tableBiew.bottomRefreshControl = nil; insets tableView reload to default.

Method for Manual End Refreshing

Hi,
I am implementing on collectionview. When i pull up the collection view, Its good working but within 1 second, loader disappear.

[refreshControl addTarget:self action:@selector(apiCallforNextPage) forControlEvents:UIControlEventValueChanged];

I want to call API when pull up and still up till get response from API. After that call endRefreshing method.

Control appear after you navigate back

Hello guys,

I meet some issues with your controller. I have 2 screens with UICollectionView. I used your control on first screen.
When I navigate to next screen and return back your control appear at the bottom.
Don't need to do anything else - just go to next screen and return back.

Best regards,
Konstantin.

AutoLayout crash

"NSLayoutConstraint for (null): Constraint must contain a first layout item"
line 222: UITableView *tableView = self.brc_context.fakeTableView; is nil

Component doesn't work in iOS 9

I've just installed XCode 7 and tested the project in iOS 9. It seems the component enters an infinite loop at the line 182 from UIScrollView+BottomRefreshControl.m: "[self brc_setContentOffset:contentOffset];"
screen shot 2015-09-20 at 8 12 47 pm

It is strange that I only use it for CollectionView and TableView but it appears as calling setContentOffset on UITextView.

Build fails

I tried to build this project with Xcode 9 after doing a pod install. I get:

ld: library not found for -lPods

self.tableView.bottomRefreshControl = nil; throwing exception

Hello Folks,

I am having trouble removing the bottomRefreshControl from my tableView. I am currently trying to do it by setting self.tableView.bottomRefreshControl = nil; but when I do so, I get a EXC_BAD_ACCESS (code=2.

How could I remove it once it is added?

Thanks,

Usage in UITableViewController

I have UITableViewController defined as follow

    @interface LogViewController : UITableViewController

in viewDidLoad i used the snippet in the home page

    UIRefreshControl *bottomRefreshControl = [UIRefreshControl new];
    [bottomRefreshControl addTarget:self action:@selector(loadMoreData) forControlEvents:UIControlEventValueChanged];
    self.tableView.bottomRefreshControl = bottomRefreshControl;

But when i open the table controller application crashes with that error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView rac_signalForSelector:]: 

which is caused from

[[self rac_signalForSelector:@selector(didMoveToSuperview)] subscribeNext:^(id x) {

            @strongify(self);
            [[self superview] insertSubview:self.context.fakeTableView aboveSubview:self];
            [self layoutFakeTableView];
        }];

in UIScrollView+BottomRefreshControl.m Line:67
obviously am using UITableViewController which is subclass from UIScrollView and in the example which is working good also TableViewController extending ScrollViewController , I need help because something is wrong maybe wrong delegate assigned early or something.

Stop Refreshing

Is there a way to stop the refreshing animation once I have refreshed my collection view?

[refreshControl endRefreshing] doesn't do anything.

Reducing the size of refresh controller

Hi I want to reduce the scroll height change. Currently I have to scroll the table a long way above to get called refresh method.

Any suggestion for this ?

The refresh icon does not disappear sometimes

Sometimes I found the app has the refresh icon at the bottom when I scroll up. It will not disappear until I scroll down to bottom again to refresh it.

If I try to reproduce it "deliberately", I can never reproduce it.

But it does happen from time to time. I have seen it several times in the past few days.

Rarely seen but it happens time to time to give weird user experience.

Crash in method brc_reloadData

0820e377-01c5-45c0-8601-87bfe3b89a0d

View controller A pushes to view controller B, and then navigate back to A while B is refreshing. What happens is that B ends refreshing after it's deallocated.

I tried the following code in B but crashes still happen.

    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        if isMovingFromParentViewController() {
            refreshControlBottom.endRefreshing()
        }
    }

Do you have any idea? Thanks so much.

Size Class Issue

After adding this library into my app, all screens stop scrolling while i am using auto layouts with size classes. I have removed this library from my app and now everything is working as expected.

No animation on updating data

After releasing the tableView activity indicator should appear under the last cell. Sometimes it appears under the last one, sometimes it is inside the last cell and sometimes it may not appear at all. And when it does not appear you do not know if the tableView already updated or not.
I set userInteractionEnabled = NO when I start downloading new data and when I got it I call "end updating", [tableView reloadData] and userInteractionEnabled = YES all together. That is how I know when table is not updated yet but refresh control not appearing.

Do you know how to make it appear each time?

Method target RefreshControl loop call

I have a problem when using bottomRefreshControl. When I load more data. In method callback from api. I endrefreshing the UIRefreshControl. But it still call the selector.
This is my method.

-(void)loadFunItems{
[[NetworkManager manager] getListFunItemsByTagId:self.tagModel.tagId andPagenumber:[NSString stringWithFormat:@"%d",pageNumber] success:^(NSMutableArray *results) {
[self.refreshControl endRefreshing];
[self.loadMoreControl endRefreshing];
if(results.count > 0){
[listFunItems addObjectsFromArray:results];
[self.tableView reloadData];
}
} failure:^(NSString *error) {
[self.refreshControl endRefreshing];
[self.loadMoreControl endRefreshing];
}];
}

-(void)loadMore{
pageNumber++;
[self loadFunItems];
}

Invisible in UITableViewController

I'm trying to use it inside of regular UITableViewContoller, it works as expected, but the control is invisible, so i cant see it

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to load more"];
refreshControl.triggerVerticalOffset = 100.;
[refreshControl addTarget:self
                   action:@selector(loadMoreEntitiesTaped:)
         forControlEvents:UIControlEventValueChanged];
self.tableView.bottomRefreshControl = refreshControl;

Remove refreshControl

Hello,

i want to remove the refreshing, the action and the control after I loaded all pages. But if i just removeTargets, removeFromSuperView() and so on, the section at the end is always like, its showing the loading indicator, without the indicator. How can I remove the RefreshControl correctly?

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.