Skip to content

Commit

Permalink
Merge pull request #6 from Alua-Kinzhebayeva/master
Browse files Browse the repository at this point in the history
fixed page resizing after orientation change
  • Loading branch information
Marxon13 committed May 1, 2015
2 parents a8c84dd + 6c151ed commit e52160d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions Classes/View/PDFKBasicPDFViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,14 @@ - (UIBarPosition)positionForBar:(id<UIBarPositioning>)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
Expand Down
8 changes: 3 additions & 5 deletions Classes/View/PDFKBasicPDFViewerSinglePageCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions Classes/View/PDFKPageContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e52160d

Please sign in to comment.