diff --git a/Classes/View/PDFKBasicPDFViewer.h b/Classes/View/PDFKBasicPDFViewer.h index 469b6c3..a1076ec 100644 --- a/Classes/View/PDFKBasicPDFViewer.h +++ b/Classes/View/PDFKBasicPDFViewer.h @@ -16,6 +16,8 @@ #import @class PDFKDocument; +typedef void (^PDFKBasicPDFViewerPageChangeBlock)(NSUInteger page); + @interface PDFKBasicPDFViewer : UIViewController /**@name Initalization*/ @@ -45,6 +47,8 @@ /**@name Properties*/ +@property (nonatomic, strong) PDFKBasicPDFViewerPageChangeBlock pageChangeBlock; + @property (nonatomic, strong, readonly) PDFKDocument *document; /**@name Features*/ diff --git a/Classes/View/PDFKBasicPDFViewer.m b/Classes/View/PDFKBasicPDFViewer.m index f293134..b90b837 100644 --- a/Classes/View/PDFKBasicPDFViewer.m +++ b/Classes/View/PDFKBasicPDFViewer.m @@ -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]; @@ -453,6 +453,10 @@ - (void)singlePageCollectionView:(PDFKBasicPDFViewerSinglePageCollectionView *)c self.document.currentPage = page; [self.pageScrubber updateScrubber]; [self resetNavigationToolbar]; + + if (_pageChangeBlock) { + _pageChangeBlock(page); + } } - (void)nextPage diff --git a/Classes/View/PDFKBasicPDFViewerSinglePageCollectionView.m b/Classes/View/PDFKBasicPDFViewerSinglePageCollectionView.m index 218d620..a5db7a6 100644 --- a/Classes/View/PDFKBasicPDFViewerSinglePageCollectionView.m +++ b/Classes/View/PDFKBasicPDFViewerSinglePageCollectionView.m @@ -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]; }