Permalink
Browse files

Whenever you get to the last page, we add a new page.

  • Loading branch information...
1 parent b1095db commit 5c74d6858a506b70a3e16ca9ae85d0fc5a7a15a5 @hollance committed Apr 30, 2011
Showing with 27 additions and 23 deletions.
  1. +2 −0 Sources/AppViewController.h
  2. +25 −23 Sources/AppViewController.m
@@ -1,6 +1,8 @@
@interface AppViewController : UIViewController <UIScrollViewDelegate>
{
+ CGSize pageSize;
+ int numPages;
}
@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;
@@ -6,35 +6,28 @@ @implementation AppViewController
@synthesize scrollView, pageControl;
-- (void)viewDidLoad
+- (void)addPageAtIndex:(int)index
{
- [super viewDidLoad];
-
- CGRect rect = [[UIScreen mainScreen] bounds];
- int numPages = 3;
-
- CGFloat pageWidth = scrollView.bounds.size.width;
- CGFloat pageHeight = scrollView.bounds.size.height;
+ CGRect rect = CGRectMake(pageSize.width * index, 0, pageSize.width, pageSize.height);
+ PageView* pageView = [[PageView alloc] initWithFrame:rect index:index];
+ [scrollView addSubview:pageView];
+ [pageView release];
- [scrollView setContentSize:CGSizeMake(numPages * pageWidth, pageHeight)];
+ numPages++;
+ [scrollView setContentSize:CGSizeMake(numPages * pageSize.width, pageSize.height)];
+ pageControl.numberOfPages = numPages;
+}
- rect = CGRectMake(0, 0, pageWidth, pageHeight);
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
- PageView* pageView = [[PageView alloc] initWithFrame:rect index:1];
- [scrollView addSubview:pageView];
- [pageView release];
+ numPages = 0;
+ pageSize = scrollView.bounds.size;
- pageView = [[PageView alloc] initWithFrame:rect index:2];
- pageView.center = CGPointMake(pageView.center.x * 3, pageView.center.y);
- [scrollView addSubview:pageView];
- [pageView release];
+ for (int t = 0; t < 2; ++t)
+ [self addPageAtIndex:t];
- pageView = [[PageView alloc] initWithFrame:rect index:3];
- pageView.center = CGPointMake(pageView.center.x * 5, pageView.center.y);
- [scrollView addSubview:pageView];
- [pageView release];
-
- pageControl.numberOfPages = numPages;
pageControl.currentPage = 0;
}
@@ -80,4 +73,13 @@ - (void)scrollViewDidScroll:(UIScrollView*)theScrollView
pageControl.currentPage = (theScrollView.contentOffset.x + width/2.0f) / width;
}
+- (void)scrollViewDidEndDecelerating:(UIScrollView*)theScrollView
+{
+ CGFloat width = theScrollView.bounds.size.width;
+ int currentPage = (theScrollView.contentOffset.x + width/2.0f) / width;
+
+ if (currentPage == numPages - 1)
+ [self addPageAtIndex:numPages];
+}
+
@end

0 comments on commit 5c74d68

Please sign in to comment.