Git Product home page Git Product logo

hgpagescrollview's Introduction

Page Scroll View.#

An extension of iOS UIScrollView that allows scrolling of multiple pages, like mobile Safari tab viewer.

HGPageScrollView uses a similar methodology to UITableView. It defines both a dataSource and a delegate, which its client can implement. At the very least HGPageScrollView expects its dataSource to provide HGPageViews to display.

Like UITableView, HGPageScrollView provides a way to improve performance by reusing pages. It maintains a queue of pages that the data source has marked for reuse. A page is marked for reuse by assigning a value to its reuseIdentifier.

Features

Scrolling horizontally through multiple views

In its basic form, HGPageScrollView shows a stack of pages, horizontally scrollable when in DECK mode (see Selection / Deselection below), where each page is a single view derived from HGPageView. The view itself is created by the data source and must be provided to HGPageScrollView in pageScrollView:viewForPageAtIndex:.

Selection / Deselection of views (aka View Modes)

HGPageScrollView has two distinct view modes:

  1. HGPageScrollViewModePage, in which the (selected) page is shown in full screen, along with its title header view.
  2. HGPageScrollViewModeDeck, in which pages can be scrolled horizontally. In this mode each page is scaled down to 60% of its original size.

Moving between the two view modes is implicit and occurs after calling selectPageAtIndex:animated: and deselectPageAnimated:.

Custom Page Headers

HGPageScrollView data source can provide custom header views to replace the default ones (seen in the exaple). A Header view is expected to have a title and a subtitle labels. The customization refers to the look and feel (size, colors etc.) of the header view.

Events

HGPageScrollView provides events to its delegate on scrolling, dragging selection and deselection of pages.

Advanced View Hierarchy (in combination with UINavigationController)

A more advanced use case, also demonstrated in this sample project, is when the page added to the page scroller actually belongs to a viewController which is part of a UINavigationController navigation stack. Doing so allows to create a rich and powerful view-hierarchy.

Inserting / Deleting / Reloading pages

HGPageScrollView supports insertion, deletion and reloading of one or more pages:

  • (void)insertPagesAtIndexes:(NSIndexSet *)indexes animated:(BOOL)animated;

  • (void)deletePagesAtIndexes:(NSIndexSet *)indexes animated:(BOOL)animated;

  • (void)reloadPagesAtIndexes:(NSIndexSet *)indexes;

Animating page insertion/deletion will only take effect if it is done within the visible page range.

Requirements

  • iOS 4.3 or later (Original sample project was created with Xcode 3.2.6, iOS SDK 4.3 GM Seed) EDIT 9 May 2012: added compatibility with iOS 5.1.

Usage

Import HGPageScrollView folder into your project.

In your ViewController's initialization code, e.g. in viewDidLoad, instantiate HGPageScrollView from its associated NIB file, as follows:

HGPageScrollView *pageScrollView = [[[NSBundle mainBundle] loadNibNamed:@"HGPageScrollView" owner:self options:nil] objectAtIndex:0];

[self.view addSubview:pageScrollView];

Declare your view controller as HGPageScrollViewDataSource and optionally as HGPageScrollViewDelegate implement at the very least the required method in this protocol: pageScrollView:viewForPageAtIndex:

You can extend HGPageView by deriving from it, or as shown in the sample project, define your custom view.xib and set it's top level item to be HGPageView class. Then simply load your view using NSBundle's loadFromNib:owner:options. Make sure to define a reuseIdentifier for your view in order to improve performance.

Known limitations

  • Does not support landscape orientation. If you're up for the challenge of adding this support, let me know...

License

HGPageScrollView is released under MIT License.

Please report bugs/issues to help improve this code.

Any suggestions and/or code to help improve this source will be much appreciated.

Thanks!

endorse

Did you find this project helpful? Please endorse me... (It's free)

hgpagescrollview's People

Contributors

hans avatar phcorcoran avatar rubnov 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hgpagescrollview's Issues

NSMutableIndexSet *indexesToReload.

in your .h file it appears as NSMutableIndexSet *indexesToReload.
but you are allocating it as NSIndexSet.

Thanks any way
Great work

Shani

issue with sample project

I was trying to scroll horizontally from the sample project and I often it crashes with the following error:

2011-12-11 05:11:34.721 HGPageScrollViewSample[9425:f803] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<MyTableViewController: 0x6e6d600> should have parent view controller:<HGPageScrollViewSampleViewController: 0x6e633c0> but actual parent is:<UINavigationController: 0x6e6d7b0>'

Sample project: reproducible crash

Steps to reproduce:

  1. Run the sample project
  2. Using the '-' button, delete all the pages
  3. Add one single new page using the '+' button
  4. Attempt to delete that page with the '-' button

There's a crash in pageScrollView:viewForPageAtIndex:, "Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds for empty array'"

Array Out of bound issue

[Session started at 2012-05-29 11:38:10 -0700.]
2012-05-29 11:40:18.146 HGPageScrollViewSample[2446:207] Completion YES
2012-05-29 11:40:22.272 HGPageScrollViewSample[2446:207] Completion NO
2012-05-29 11:40:43.039 HGPageScrollViewSample[2446:207] Completion YES
2012-05-29 11:40:44.905 HGPageScrollViewSample[2446:207] Completion NO
2012-05-29 11:40:46.695 HGPageScrollViewSample[2446:207] Completion YES
2012-05-29 11:40:47.831 HGPageScrollViewSample[2446:207] Completion NO
2012-05-29 12:23:37.462 HGPageScrollViewSample[2446:207] Completion YES
2012-05-29 12:23:39.147 HGPageScrollViewSample[2446:207] Completion NO
2012-05-29 12:23:40.436 HGPageScrollViewSample[2446:207] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSMutableArray objectAtIndex:]: index 2147483646 beyond bounds [0 .. 2]'
*** Call stack at first throw:
(
0 CoreFoundation 0x00f29be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0107e5c2 objc_exception_throw + 47
2 CoreFoundation 0x00f1f6e5 -[__NSArrayM objectAtIndex:] + 261
3 HGPageScrollViewSample 0x0000bf4e -[HGPageScrollView scrollViewDidScroll:] + 878
4 HGPageScrollViewSample 0x0000aff3 -[HGPageScrollView deletePagesAtIndexes:animated:] + 2035
5 HGPageScrollViewSample 0x0000435b -[HGPageScrollViewSampleViewController removePagesAtIndexSet:] + 203
6 HGPageScrollViewSample 0x0000424f -[HGPageScrollViewSampleViewController didClickRemovePage:] + 335

Multiple scrolling

Can I disable scrolling on two screens? I need to scroll no more than one.

Issues with implementation

I'm trying the base implementation, but just can't seem to find a way to get this to work.

In my h file.
``

import <UIKit/UIKit.h>

import "HGPageScrollView.h"

@interface MyScrollViewController : UIViewController <HGPageScrollViewDataSource, HGPageScrollViewDelegate>``

and m:

#import "MyScrollViewController.h"

@interface MyScrollViewController ()

@end

@implementation MyScrollViewController

- (void)viewDidLoad
`{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
HGPageScrollView *pageScrollView = [[[NSBundle mainBundle] loadNibNamed:@"HGPageScrollView" owner:self options:nil] objectAtIndex:0];
[self.view addSubview:pageScrollView];
}
``

In your markdown you note

least the required method in this protocol: pageScrollView:viewForPageAtIndex: But I dont really see anywhere that details this.

I tried mimicing what was in the sample file but I keep returning:

2012-09-10 14:25:48.913 MyScroll[21002:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:

Hi,I run sample HGPageScrollView crash. Help...

Hi:
I run(iPhone4 (iOS5, Xcode 4.2)) HGPageScrollView crash.I's crash log:

*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<MyTableViewController: 0x1cc060> should have parent view controller:<HGPageScrollViewSampleViewController: 0x1c3860> but actual parent is:<UINavigationController: 0x1ccdf0>'
*** First throw call stack:
(0x341698bf 0x358851e5 0x341697b9 0x341697db 0x352181b9 0x351d97ef 0x351d92bf 0x351d918b 0x51c3 0x35b3 0x340c3435 0x351f19eb 0x352b73cf 0x340c3435 0x351f19eb 0x351f19a7 0x351f1985 0x351f16f5 0x351f202d 0x351f050f 0x351eff01 0x351d64ed 0x351d5d2d 0x35d00df3 0x3413d553 0x3413d4f5 0x3413c343 0x340bf4dd 0x340bf3a5 0x35cfffcd 0x35204743 0x211d 0x20dc)

help me.

Apple match-O link error

Hi I am making a web browser and I want to implement multi tab feature, so I downloaded HGPageScrollview and tried to run it in Xcode 6 but it got the following error.
screen shot 2015-05-08 at 2 58 45 pm
Can you please tell me the solution for 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.