Skip to content

Commit

Permalink
Fixed page calculation, added method that is called after tapping, ad…
Browse files Browse the repository at this point in the history
…ded block that is called after page change.
  • Loading branch information
Kamil Burczyk committed Jun 25, 2015
1 parent de99828 commit 3e2fde7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 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
4 changes: 4 additions & 0 deletions Classes/View/PDFKBasicPDFViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 3e2fde7

Please sign in to comment.