Coder Social home page Coder Social logo

tonyzonghui / ispagescrollview Goto Github PK

View Code? Open in Web Editor NEW
23.0 4.0 4.0 138 KB

A page scroll view which allows infinite scrolling (not looping). This scroll view is optimised for huge number of pages display.

License: MIT License

Objective-C 83.33% Ruby 16.67%

ispagescrollview's Introduction

ISPageScrollView

Note: This is a sub-project of UIKitHelper git project. You may want to use UIKitHelper in your project for more UIKit utilities.


Description

ISPageScrollView is a UIScrollView subclass optimised for huge number of pages display. It uses lazy-loading mechanism to maintain only the previous few pages and the next few pages in order to minimize the memory usage.

Properties:

id<ISPageScrollViewDataSource> dataSource: Like UITableViewDataSource, it asks its dataSource object for views displayed in each page.

id<ISPageScrollViewDelegate> pageDelegate: Tells receiver when a page will be removed from cache, has been removed from cache or when the displayed page changed.

NSInteger numberOfReusablePages: number of pages maintanined in memory. This number should be an odd number (e.g: 5 = current displayed page + 2 pages in front + 2 pages after)

NSMutableDictionary readonly scrollViewAvailablePages: this is the dictionary that stores the views of the pages in memory. The keys for the dictionary are NSNumbers for page index. The values for each key is an UIView object.

DataSource required methods

*-viewForScrollView:(ISPageScrollView )scrollView page:(NSInteger)pageIndex: Needs to return the view to use on specified page.

*-numberOfPagesForPageScrollView:(ISPageScrollView )scrollView: Needs to return the number of pages in the scroll view.

Usage

It can be created in xcode like UIScollView or can be created programatically.

ISPageScrollView *pageScrollView = [[ISPageScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
pageScrollView.dataSource = self;
pageScrollView.numberOfReusableViews = 5;

[pageScrollView displayPage:0];

Also implement both methods of the datasource.

License

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

ispagescrollview's People

Contributors

bzhang443 avatar joskuijpers avatar tonyzonghui 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

Watchers

 avatar  avatar  avatar  avatar

ispagescrollview's Issues

NSRangeException - beyond bounds

When _numberOfPages and numberOfReusable views are equal, this raises an NSRangeException (beyond bounds). )I think in line 100 of ISPageScrollView:
NSInteger maxPageIndex = MIN(_numberOfPages, pageIndex + (_numberOfReusableViews - 1) / 2.0);

it should be

NSInteger maxPageIndex = MIN(_numberOfPages - 1, pageIndex + (_numberOfReusableViews - 1) / 2.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.