Code Monkey home page Code Monkey logo

gbinfinitescrollview's Introduction

GBInfiniteScrollView

GBInfiniteScrollView class provides an endlessly scroll view organized in pages. It is a subclass of UIScrollView, which allows users to scroll infinitely in horizontal and vertical direction. GBInfiniteScrollView also provides automatic scrolling feature.

A GBInfiniteScrollView object must have an object that acts as a data source and an object that acts as a delegate. The data source must adopt the GBInfiniteScrollViewDataSource protocol and the delegate must adopt the GBInfiniteScrollViewDelegate protocol. The data source provides the views that GBInfiniteScrollView needs to display. The delegate allows the adopting delegate to respond to scrolling operations.

GBInfiniteScrollView overrides the layoutSubviews method of UIView so that it calls reloadData only when you create a new instance of GBInfiniteScrollView or when you assign a new data source. Reloading the infinite scroll view clears current state, including the current view, but it is possible to specify the initial page index to display.

It is based on Apple StreetScroller iOS sample code.

Requirements

GBInfiniteScrollView works on iOS 6.1 SDK or later and is compatible with ARC projects.

Adding GBInfiniteScrollView to your project

CocoaPods

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

  1. Add a pod entry for GBInfiniteScrollView to your Podfile pod 'GBInfiniteScrollView', '~> 1.8'
  2. Install the pod(s) by running pod install.
  3. Include GBInfiniteScrollView wherever you need it with #import <GBInfiniteScrollView/GBInfiniteScrollView.h>.

For the page control subclass.

  1. Add a pod entry for GBInfiniteScrollView/PageControl to your Podfile pod 'GBInfiniteScrollView/PageControl'
  2. Install the pod(s) by running pod install.
  3. Include GBInfiniteScrollViewWithPageControl wherever you need it with #import <GBInfiniteScrollView/GBInfiniteScrollViewWithPageControl.h>.

Source files

You can directly add the header and implementation files to your project.

  1. Download the latest code version.
  2. Open your project in Xcode, then drag and drop the header and implementation files onto your project (use the "Product Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project.
  3. Include GBInfiniteScrollView wherever you need it with #import <GBInfiniteScrollView/GBInfiniteScrollView.h>.

Static library

You can also add GBInfiniteScrollView as a static library to your project or workspace.

  1. Download the latest code version or add the repository as a git submodule to your git-tracked project.
  2. Open your project in Xcode, then drag and drop GBInfiniteScrollView.xcodeproj onto your project or workspace (use the "Product Navigator view").
  3. Select your target and go to the Build phases tab. In the Link Binary With Libraries section select the add button. On the sheet find and add libGBInfiniteScrollView.a. You might also need to add GBInfiniteScrollView to the Target Dependencies list.
  4. Include GBInfiniteScrollView wherever you need it with #import <GBInfiniteScrollView/GBInfiniteScrollView.h>.

Usage

This is an example of use:

First, import GBInfiniteScrollView lib. Your view controller must conform to the GBInfiniteScrollViewDataSource and GBInfiniteScrollViewDelegate protocols.

#import <UIKit/UIKit.h>

#import <GBInfiniteScrollView/GBInfiniteScrollView.h>

@interface GBViewController : UIViewController <GBInfiniteScrollViewDataSource, GBInfiniteScrollViewDelegate>

@end

Then, initialize a GBInfiniteScrollView new instance.

GBInfiniteScrollView *infiniteScrollView = [[GBInfiniteScrollView alloc] initWithFrame:self.view.bounds];

infiniteScrollView.infiniteScrollViewDataSource = self;
infiniteScrollView.infiniteScrollViewDelegate = self;

infiniteScrollView.pageIndex = 0;
    
[self.view addSubview:infiniteScrollView];
    
[infiniteScrollView reloadData];

[infiniteScrollView startAutoScroll];

Finally, implement the GBInfiniteScrollViewDataSource and GBInfiniteScrollViewDelegate protocols methods.

- (void)infiniteScrollViewDidScrollNextPage:(GBInfiniteScrollView *)infiniteScrollView
{
    NSLog(@"Next page");
}

- (void)infiniteScrollViewDidScrollPreviousPage:(GBInfiniteScrollView *)infiniteScrollView
{
    NSLog(@"Previous page");
}

- (BOOL)infiniteScrollViewShouldScrollNextPage:(GBInfiniteScrollView *)infiniteScrollView
{
    return YES;
}

- (BOOL)infiniteScrollViewShouldScrollPreviousPage:(GBInfiniteScrollView *)infiniteScrollView
{
    return YES;
}

- (NSInteger)numberOfPagesInInfiniteScrollView:(GBInfiniteScrollView *)infiniteScrollView
{
    return self.data.count;
}

- (GBInfiniteScrollViewPage *)infiniteScrollView:(GBInfiniteScrollView *)infiniteScrollView pageAtIndex:(NSUInteger)index;
{
    GBPageRecord *record = [self.data objectAtIndex:index];
    GBInfiniteScrollViewPage *page = [infiniteScrollView dequeueReusablePage];
    
    if (page == nil) {
        page = [[GBInfiniteScrollViewPage alloc] initWithFrame:self.view.bounds style:GBInfiniteScrollViewPageStyleText];
    }
    
    page.textLabel.text = record.text;
    page.textLabel.textColor = record.textColor;
    page.contentView.backgroundColor = record.backgroundColor;
    page.textLabel.font = [UIFont fontWithName: @"HelveticaNeue-UltraLight" size:128.0f];
    
    return page;
}

License

The MIT License (MIT)

Copyright (c) 2013 Gerardo Blanco

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gbinfinitescrollview's People

Contributors

942v avatar candyan avatar cvertex avatar gblancogarcia avatar kylexie avatar phatmann avatar readmecritic avatar sonifex avatar sstorkel avatar xhzengaib 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

gbinfinitescrollview's Issues

iOS6.1 support?

I'm already using your lib in two of my apps. I'd like to know if it's possible that you modify GBInfiniteScollView to support iOS 6.1. That will be ABSOLUTELY perfect.
Thank you very much.

fast scrolling

Hi, good control but:

autoscrolling is very fast, how can i change it?
I'm talking about setContentOffset animation duration (not about property "interval")

Reload current page

When I call reloadData or updateData the current page doesn't update.

How can I solve this?

Thanks.

Assertion failure when used with Auto Layout on iOS 7

*** Assertion failure in -[GBInfiniteScrollView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2935.137/UIView.m:8794
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. GBInfiniteScrollView's implementation of -layoutSubviews needs to call super.'

Tried adding the [super layoutSubviews] at the end of the the layoutSubviews method and it removed the crash, but I'm not sure if that is the solution

productPurchased:product.productIdentifier can't be captured when demo run and scroll view page index == 0

I added IAP function in - (NSInteger)numberOfPagesInInfiniteScrollView:(GBInfiniteScrollView *)infiniteScrollView, like below

- (GBInfiniteScrollViewPage *)infiniteScrollView:(GBInfiniteScrollView *)infiniteScrollView pageAtIndex:(NSUInteger)index;
{
    . . . . . . Original Demo Code Omitted. . . . . . 

    // added for IAP
    if (index == 0) {
        SKProduct * product = (SKProduct *) [_products objectAtIndex:0];
        BOOL productPurchased = [[SSIAPHelper sharedInstance] productPurchased:product.productIdentifier];
        if (productPurchased) {
            NSLog(@"BOOL is %hhd", productPurchased);
        } else
            NSLog(@"BOOL is %hhd ", productPurchased);
        if (productPurchased) {
            UIAlertView * purchasedAlert = [[UIAlertView alloc] initWithTitle:@"Purchased"
                                                                 message:nil delegate:self
                                                       cancelButtonTitle:@"OK"
                                                       otherButtonTitles:nil];
            purchasedAlert.tag = 100;
            [purchasedAlert show];
        } else {
            UIAlertView * notPurchasedAlert = [[UIAlertView alloc] initWithTitle:@"NOT Purchased"
                                                                 message:nil delegate:self
                                                       cancelButtonTitle:@"Buy"
                                                       otherButtonTitles:@"Cancel", nil];
            notPurchasedAlert.tag = 200;
            [notPurchasedAlert show];
        }
    }
}

Run the demo the first time, definitely, will show NOT Purchased alert view to remind purchase, then buy it. Then sliding to left direction or right and then sliding back to page index == 0, will show Purchased alert view. So, IAP is implemented correctly.

After pressing iPhone Home key, and killing the demo process, then run the demo again, page index == 0 is going to be presented. But, NOT Purchased alert view is also popping out. Putting NSLog there shows productPurchased:product.productIdentifier not get successfully.

The second thing is, tap the Cancel, then sliding to left or right direction, and then sliding back to index == 0, it's popping out the Purchased alert view!

Oops, looks product.productIdentifier can't be retrieved when showing page at index is 0! Do you know why it is? How to fix this?

Appreicated a lot in advance!

Swift code

Does anyone have Swift version using of library?

pageAtIndex picking up wrong object for page index 0

Hi. I've an NSArray of custom objects i'm using, each of which contains a pointer to either an ALAssets URL or NSURL of photo on the internet. If i

setPageIndex:0
(or do nothing, which i believe defaults the pageIndex to 0)

the first time i call reloadData, the second image in the array gets pulled. This only happens when the pageIndex is 0. My workaround is currently to set the page index to 1, reloadData, then set it to 0 and reloadData

[self.photosInfiniteScrollView setPageIndex:1];
[self.photosInfiniteScrollView reloadData];
[self.photosInfiniteScrollView setPageIndex:0];
[self.photosInfiniteScrollView reloadData];

What i've observed is that with pageIndex:0, a call to reloadData never ends up calling my pageAtIndex method, because of code in GBInfiniteScrollView.m:

  • (GBInfiniteScrollViewPage *)pageAtIndex:(NSUInteger)index
    {
    GBInfiniteScrollViewPage *page = nil;

    NSUInteger visibleIndex = [self.visibleIndices indexOfObject:[NSNumber numberWithUnsignedInteger:index]];

    if (visibleIndex != NSNotFound) {
    page = [self.visiblePages objectAtIndex:visibleIndex];
    } else if (self.infiniteScrollViewDataSource &&
    [self.infiniteScrollViewDataSource respondsToSelector:@selector(infiniteScrollView:pageAtIndex:)]) {
    page = [self.infiniteScrollViewDataSource infiniteScrollView:self pageAtIndex:index];
    }

    return page;
    }

visibleIndex != NSNotFound evaluates to true, so it just pulls objectAtIndex:visibleIndex

That's as far as i've gotten with it; i'm posting now thinking maybe you'll see something sooner than I will, but in the meantime I have the workaround in place, while also trying to understand your code better to further debug it.

NSLog twice if page index is 0

Just run your demo intactly and found page at index = 0 is to NSLog twice

 Infinite[284:60b] Page at index 0
 Infinite[284:60b] Page at index 0

If just this, ok. But if there is UIAlertView that's going to be put on page at index = 0, the alert view will pop out twice.

How to fix this? Thanks!

Need reset page control while reload data

I found that if I setup a GBInfiniteScrollViewWithPageControl in interface builder, the page control will not showing. The reason is that you only setup the page control when the scroll view move to super view or a user scroll the view. I think maybe the better time to setup the page control is when reload data.

Best Regards

Update minimum pod version to 6.1

I tried to update my app to support 6.1, so I added a GBInfiniteScrollView entry in the pod file, but when updating I have this:
The platform of the target Pods (iOS 6.1) is not compatible with GBInfiniteScrollView (1.0) which has a minimum requirement of iOS 7.0.

Can you please update the pod version to support 6.1 ?

Thank you.

Bottom dots

Hi,
Can you please add the possibility to add bottom dots (like in the UIPageController)?

Thank you very much.

Supporting pull down to refresh, or refresh at the last screen

Hi -- I'm trying to get pull-down to refresh work with this library when you are at the first or last page. Any idea how to get this to work? (The standard libraries like UIRefreshControl or SVPullDownToRefresh don't seem to work as-is because I've got my shouldScrollToPreviousPage and shouldScrollToNextPage return False in both these cases)

Thanks!

GBInfiniteScrollViewPageStyleImage

I have set the direction to GBAutoScrollDirectionRightToLeft with GBInfiniteScrollViewPageStyleImage, the problem is that when I scroll horizontally it bounces vertically by 20 pixels (the size of the status bar).

Here is my setup:

self.autoScrollDirection = GBAutoScrollDirectionRightToLeft;
self.infiniteScrollView = [[GBInfiniteScrollViewWithPageControl alloc] initWithFrame:self.myView.frame];
self.infiniteScrollView.infiniteScrollViewDataSource = self;
self.infiniteScrollView.infiniteScrollViewDelegate = self;
self.infiniteScrollView.debug = self.debug;
self.infiniteScrollView.verboseDebug = verboseDebug;
self.infiniteScrollView.interval = 4.0f;
self.infiniteScrollView.pageIndex = 0; //131 199 228
self.infiniteScrollView.autoScrollDirection = self.autoScrollDirection;
self.infiniteScrollView.scrollDirection = GBScrollDirectionHorizontal;
self.infiniteScrollView.pageControlViewContainer.hidden = YES;
[self.myView addSubview:self.infiniteScrollView];

[self.infiniteScrollView reloadData];

[self.infiniteScrollView startAutoScroll];

Bug when GBInfiniteScrollView in a controller which is invisible.

I create a GBInfiniteScrollView instance on my viewController A, start AutoScroll, there is also a button on it, when I click it to push a new viewcontroller B, wait for a more than 3(default auto scroll duration is 3 seconds) seconds, click back button the show this viewcontrller A, contentView of GBInfiniteScrollView is blank, what's wrong?

"Add" not instantly

Not sure this is an issue, but it has such situations.

When view of index = 0 is showing, tap "Add", then sliding the view from left to right, which is supposed to show the new last view just added, index = 1000, but still show the old last view of index = 999. Happens same on when showing view of index = 999, then "add", then sliding, what would be seen is the view of index = 0, instead of view of index = 1000.

If view of index = 998 or = 1, then "add", will show the latest added last view correctly.

Error scroll direction

line: 466
expected: [self didScrollToPreviousPage];

if (currentContentOffset.x == [self minContentOffsetX]) {
[self previous];
[self didScrollToNextPage];
} else if (currentContentOffset.x == [self maxContentOffsetX]) {
[self next];
[self didScrollToNextPage];
}

Custom page

Hello, whats the best way to custom page view?

  • (GBInfiniteScrollViewPage *)infiniteScrollView:(GBInfiniteScrollView *)infiniteScrollView pageAtIndex:(NSUInteger)index;

must return GBInfiniteScrollViewPage

Memory management

I'm trying to add more than 500 views in the whole GBInfiniteScrollView.
The views contains just UILabels(No UIImageViews).
I'm getting a crash when reached approximately the 80th view.
Is there any possibility to update the lib to well manage memory leaks?

Thank you very much.

How to set different time interval during autoscroll?

Tried to pass a NSTimeInterval value to self.infiniScrollView.interval, but it's constant, not changed according to time settings for different scrolling pages.

My intention is to start auto scroll after "auto scroll" button pressed, then it could auto scroll at a flexible time interval which are linked to every scrolling page, because the shown time of every page is dynamic.

How to do that? Thanks!

Update this Cocoapod in pods repo

Howdy,

I'm reviewing my Podfile and noticed the GBInfiniteScrollView in the official pod repo is out of date.

Is it lots of work to update the official pod?

This makes this pod easier to discover

"startAutoScroll" memory leak

Hi,
I just want to mention that there is a memory leak on the startAutoScroll method, when I do not choose to auto scroll all is working fine with the app memory, by against, the app memory is going like crazy when "[self.infiniteScrollView startAutoScroll];" is enabled.
Can you please check it. Thanks !

Empty view after returning from another view controller.

When I'm returning from another view controller using [self.navigationController popViewController], I found out, that my scrollView is empty. Only after regular delay next page appears from right, as usual. Method -updateData in -viewDidAppear saves me now, but I think, it's not the best way :) Thank you!

auto layout support ?

Hi,

I would like to support auto layout in the next release of my app, but it seems that the scroll view doesn't support it... Do you have any directions for me about that ?

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.