Skip to content

Commit e3629c5

Browse files
author
Ryan Maxwell
committed
Implement fast-pagination
1 parent ff5249b commit e3629c5

1 file changed

Lines changed: 34 additions & 20 deletions

File tree

Sources/ReaderViewController.m

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ @implementation ReaderViewController
5353
UIPrintInteractionController *printInteraction;
5454

5555
NSInteger currentPage;
56+
57+
NSInteger currentScrollViewPage;
5658

5759
CGSize lastAppearSize;
5860

@@ -436,7 +438,7 @@ - (void)viewDidUnload
436438

437439
theScrollView = nil; contentViews = nil; lastHideTime = nil;
438440

439-
lastAppearSize = CGSizeZero; currentPage = 0;
441+
lastAppearSize = CGSizeZero; currentPage = 0; currentScrollViewPage = 0;
440442

441443
[super viewDidUnload];
442444
}
@@ -500,25 +502,37 @@ - (void)dealloc
500502

501503
#pragma mark UIScrollViewDelegate methods
502504

503-
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
504-
{
505-
__block NSInteger page = 0;
506-
507-
CGFloat contentOffsetX = scrollView.contentOffset.x;
508-
509-
[contentViews enumerateKeysAndObjectsUsingBlock: // Enumerate content views
510-
^(id key, id object, BOOL *stop)
511-
{
512-
ReaderContentView *contentView = object;
513-
514-
if (contentView.frame.origin.x == contentOffsetX)
515-
{
516-
page = contentView.tag; *stop = YES;
517-
}
518-
}
519-
];
520-
521-
if (page != 0) [self showDocumentPage:page]; // Show the page
505+
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
506+
{
507+
NSInteger scrollViewPage = 0;
508+
CGFloat pageWidth = scrollView.frame.size.width;
509+
CGFloat contentOffsetX = scrollView.contentOffset.x;
510+
511+
if ((currentScrollViewPage == 0 && contentOffsetX < pageWidth) || contentOffsetX <= 0) {
512+
scrollViewPage = 0;
513+
} else if ((currentScrollViewPage == 2 && contentOffsetX <= pageWidth) || (currentScrollViewPage != 2 && contentOffsetX < 2 * pageWidth)) {
514+
scrollViewPage = 1;
515+
} else {
516+
scrollViewPage = 2;
517+
}
518+
519+
if (scrollViewPage != currentScrollViewPage) {
520+
currentScrollViewPage = scrollViewPage;
521+
522+
CGFloat contentOffsetX = scrollView.frame.size.width * scrollViewPage;
523+
524+
__block NSInteger page = 0;
525+
526+
[contentViews enumerateKeysAndObjectsUsingBlock:^(id key, ReaderContentView *contentView, BOOL *stop) {
527+
if (contentView.frame.origin.x == contentOffsetX) {
528+
page = contentView.tag; *stop = YES;
529+
}
530+
}];
531+
532+
if (page != 0) {
533+
[self showDocumentPage:page]; // Show the page
534+
}
535+
}
522536
}
523537

524538
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

0 commit comments

Comments
 (0)