From 6c151edba4053a497c90fd38b6e0e63f50399f14 Mon Sep 17 00:00:00 2001 From: "Alua.Kinzhebayeva" Date: Sat, 25 Apr 2015 04:58:20 +0600 Subject: [PATCH] fixed page resizing after orientation change --- Classes/View/PDFKBasicPDFViewer.m | 9 +++++---- .../View/PDFKBasicPDFViewerSinglePageCollectionView.m | 8 +++----- Classes/View/PDFKPageContentView.m | 6 ++++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Classes/View/PDFKBasicPDFViewer.m b/Classes/View/PDFKBasicPDFViewer.m index 362950d..7809ba3 100644 --- a/Classes/View/PDFKBasicPDFViewer.m +++ b/Classes/View/PDFKBasicPDFViewer.m @@ -257,13 +257,14 @@ - (UIBarPosition)positionForBar:(id)bar return UIBarPositionBottom; } -- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration -{ - //Invalidate the layouts of the collection views on rotation, and animate the rotation. - [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; +-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ + [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; [_thumbsCollectionView.collectionViewLayout invalidateLayout]; [_pageCollectionView.collectionViewLayout invalidateLayout]; + + [_pageCollectionView displayPage:_document.currentPage animated:NO]; + } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation diff --git a/Classes/View/PDFKBasicPDFViewerSinglePageCollectionView.m b/Classes/View/PDFKBasicPDFViewerSinglePageCollectionView.m index 3aadd84..218d620 100644 --- a/Classes/View/PDFKBasicPDFViewerSinglePageCollectionView.m +++ b/Classes/View/PDFKBasicPDFViewerSinglePageCollectionView.m @@ -87,6 +87,8 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell //Get the page number NSInteger page = indexPath.row + 1; + cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; + //Load the content cell.pageContentView = [[PDFKPageContentView alloc] initWithFrame:contentSize fileURL:_document.fileURL page:page password:_document.password]; @@ -121,12 +123,8 @@ - (void)setPageContentView:(PDFKPageContentView *)pageContentView } _pageContentView = pageContentView; - _pageContentView.translatesAutoresizingMaskIntoConstraints = NO; + [self.contentView addSubview:_pageContentView]; - - NSMutableArray *constraints = [[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[content]|" options:NSLayoutFormatAlignAllBaseline metrics:nil views:@{@"superview": self.contentView, @"content": _pageContentView}] mutableCopy]; - [constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[content]|" options:NSLayoutFormatAlignAllLeft metrics:nil views:@{@"superview": self.contentView, @"content": _pageContentView}]]; - [self.contentView addConstraints:constraints]; } - (void)layoutSubviews diff --git a/Classes/View/PDFKPageContentView.m b/Classes/View/PDFKPageContentView.m index 111cc9c..dd68740 100644 --- a/Classes/View/PDFKPageContentView.m +++ b/Classes/View/PDFKPageContentView.m @@ -88,11 +88,13 @@ - (id)initWithFrame:(CGRect)frame fileURL:(NSURL *)fileURL page:(NSUInteger)page { theContainerView = [[UIView alloc] initWithFrame:theContentView.bounds]; theContainerView.backgroundColor = [UIColor blueColor]; - theContainerView.autoresizesSubviews = NO; theContainerView.userInteractionEnabled = NO; theContainerView.contentMode = UIViewContentModeRedraw; - theContainerView.autoresizingMask = UIViewAutoresizingNone; theContainerView.backgroundColor = [UIColor whiteColor]; + theContainerView.autoresizesSubviews = YES; + theContainerView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; + + self.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; //Remove autoresizing constraints. theContentView.translatesAutoresizingMaskIntoConstraints = NO;