Skip to content

Commit

Permalink
Merge pull request #10 from Sigmapoint/develop
Browse files Browse the repository at this point in the history
Fixed page calculation, added notification block
  • Loading branch information
Marxon13 committed Jun 26, 2015
2 parents de99828 + d94dc77 commit 976da11
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Classes/View/PDFKBasicPDFViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#import <UIKit/UIKit.h>
@class PDFKDocument;

typedef void (^PDFKBasicPDFViewerPageChangeBlock)(NSUInteger page);

@interface PDFKBasicPDFViewer : UIViewController

/**@name Initalization*/
Expand Down Expand Up @@ -45,6 +47,8 @@

/**@name Properties*/

@property (nonatomic, strong) PDFKBasicPDFViewerPageChangeBlock pageChangeBlock;

@property (nonatomic, strong, readonly) PDFKDocument *document;

/**@name Features*/
Expand Down
6 changes: 5 additions & 1 deletion Classes/View/PDFKBasicPDFViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ - (void)toggleShowBookmarks:(id)sender

- (void)thumbCollectionView:(PDFKBasicPDFViewerThumbsCollectionView *)thumbsCollectionView didSelectPage:(NSUInteger)page
{
[self.pageCollectionView displayPage:page animated:NO];
[self.pageCollectionView displayPage:page animated:YES];
self.document.currentPage = page;
[self.pageScrubber updateScrubber];
[self toggleSinglePageView];
Expand All @@ -453,6 +453,10 @@ - (void)singlePageCollectionView:(PDFKBasicPDFViewerSinglePageCollectionView *)c
self.document.currentPage = page;
[self.pageScrubber updateScrubber];
[self resetNavigationToolbar];

if (_pageChangeBlock) {
_pageChangeBlock(page);
}
}

- (void)nextPage
Expand Down
13 changes: 10 additions & 3 deletions Classes/View/PDFKBasicPDFViewerSinglePageCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//Get the current cell and notify the delegate
NSIndexPath *indexPath = [self indexPathsForVisibleItems][0];
NSUInteger page = indexPath.row + 1;
//Get the current page and notify the delegate
NSUInteger page = (scrollView.contentOffset.x + scrollView.frame.size.width) / scrollView.frame.size.width;

[_singlePageDelegate singlePageCollectionView:self didDisplayPage:page];
}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
//Get the current page and notify the delegate
NSUInteger page = (scrollView.contentOffset.x + scrollView.frame.size.width) / scrollView.frame.size.width;

[_singlePageDelegate singlePageCollectionView:self didDisplayPage:page];
}
Expand Down

0 comments on commit 976da11

Please sign in to comment.