|
@@ -20,6 +20,10 @@
|
|
|
|
|
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
|
|
|
|
|
|
|
+@property (nonatomic, strong) UILabel *titleLabel;
|
|
|
|
+
|
|
|
|
+@property (nonatomic, strong) UIButton *backBtn;
|
|
|
|
+
|
|
@end
|
|
@end
|
|
|
|
|
|
@implementation CPDFThumbnailViewController
|
|
@implementation CPDFThumbnailViewController
|
|
@@ -40,7 +44,6 @@
|
|
- (void)viewDidLoad {
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
// Do any additional setup after loading the view.
|
|
- self.title = @"Thumbnail";
|
|
|
|
[self changeleftItem];
|
|
[self changeleftItem];
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.itemSize = CGSizeMake(110, 185);
|
|
layout.itemSize = CGSizeMake(110, 185);
|
|
@@ -49,7 +52,7 @@
|
|
layout.minimumLineSpacing = 5;
|
|
layout.minimumLineSpacing = 5;
|
|
|
|
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
|
|
- [self.collectionView registerClass:[CPDFThumbnailViewCell class] forCellWithReuseIdentifier:@"cell"];
|
|
|
|
|
|
+ [self.collectionView registerClass:[CPDFThumbnailViewCell class] forCellWithReuseIdentifier:@"thumnailCell"];
|
|
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
|
|
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
|
|
self.collectionView.delegate = self;
|
|
self.collectionView.delegate = self;
|
|
self.collectionView.dataSource = self;
|
|
self.collectionView.dataSource = self;
|
|
@@ -58,26 +61,87 @@
|
|
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
|
|
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ self.view.backgroundColor = [UIColor whiteColor];
|
|
|
|
+ self.collectionView.backgroundColor = [UIColor colorWithRed:0.804 green:0.804 blue:0.804 alpha:1];
|
|
|
|
+
|
|
[self.view addSubview:self.collectionView];
|
|
[self.view addSubview:self.collectionView];
|
|
|
|
+
|
|
|
|
+ [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
|
|
|
|
+
|
|
|
|
+ self.titleLabel = [[UILabel alloc] init];
|
|
|
|
+ self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
|
|
|
|
+
|
|
|
|
+ self.titleLabel.text = NSLocalizedString(@"Thumbnail", nil);
|
|
|
|
+ self.titleLabel.font = [UIFont systemFontOfSize:20];
|
|
|
|
+ self.titleLabel.adjustsFontSizeToFitWidth = YES;
|
|
|
|
+ [self.view addSubview:self.titleLabel];
|
|
|
|
+
|
|
|
|
+ self.backBtn = [[UIButton alloc] init];
|
|
|
|
+ self.backBtn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
|
|
|
|
+ [self.backBtn setImage:[UIImage imageNamed:@"CPDFEditClose" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
|
+ [self.backBtn addTarget:self action:@selector(buttonItemClicked_back:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
+ [self.view addSubview:self.backBtn];
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)buttonItemClicked_back:(UIButton *)button {
|
|
|
|
+ [self dismissViewControllerAnimated:YES completion:^{
|
|
|
|
+
|
|
|
|
+ }];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
|
|
|
+ [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
|
|
|
|
+ [self updatePreferredContentSizeWithTraitCollection:newCollection];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection
|
|
|
|
+{
|
|
|
|
+ self.preferredContentSize = CGSizeMake(self.view.bounds.size.width,self.view.bounds.size.height * 0.9);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+- (void)viewWillLayoutSubviews {
|
|
|
|
+
|
|
|
|
+ if (@available(iOS 11.0, *)) {
|
|
|
|
+
|
|
|
|
+ self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, 50);
|
|
|
|
+
|
|
|
|
+ self.collectionView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 50, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - 50 - self.view.safeAreaInsets.top);
|
|
|
|
+ self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 50);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, 50);
|
|
|
|
+ self.collectionView.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 50);
|
|
|
|
+ self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 50);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
[self.collectionView reloadData];
|
|
[self.collectionView reloadData];
|
|
|
|
+
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.pdfView.currentPageIndex inSection:0];
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.pdfView.currentPageIndex inSection:0];
|
|
[self.collectionView selectItemAtIndexPath:indexPath
|
|
[self.collectionView selectItemAtIndexPath:indexPath
|
|
animated:NO
|
|
animated:NO
|
|
scrollPosition:UICollectionViewScrollPositionCenteredVertically];
|
|
scrollPosition:UICollectionViewScrollPositionCenteredVertically];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
[super viewDidAppear:animated];
|
|
[super viewDidAppear:animated];
|
|
-
|
|
|
|
|
|
+
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.pdfView.currentPageIndex inSection:0];
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.pdfView.currentPageIndex inSection:0];
|
|
[self.collectionView scrollToItemAtIndexPath:indexPath
|
|
[self.collectionView scrollToItemAtIndexPath:indexPath
|
|
atScrollPosition:UICollectionViewScrollPositionCenteredVertically
|
|
atScrollPosition:UICollectionViewScrollPositionCenteredVertically
|
|
animated:YES];
|
|
animated:YES];
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
#pragma mark - Class method
|
|
#pragma mark - Class method
|
|
@@ -99,7 +163,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- CPDFThumbnailViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
|
|
|
|
|
|
+ CPDFThumbnailViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"thumnailCell" forIndexPath:indexPath];
|
|
CPDFPage *page = [self.pdfView.document pageAtIndex:indexPath.item];
|
|
CPDFPage *page = [self.pdfView.document pageAtIndex:indexPath.item];
|
|
CGSize pageSize = [self.pdfView.document pageSizeAtIndex:indexPath.item];
|
|
CGSize pageSize = [self.pdfView.document pageSizeAtIndex:indexPath.item];
|
|
CGFloat multiple = MAX(pageSize.width / 110, pageSize.height / 173);
|
|
CGFloat multiple = MAX(pageSize.width / 110, pageSize.height / 173);
|
|
@@ -114,9 +178,14 @@
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
|
|
+
|
|
if([self.delegate respondsToSelector:@selector(thumbnailViewController:pageIndex:)]) {
|
|
if([self.delegate respondsToSelector:@selector(thumbnailViewController:pageIndex:)]) {
|
|
[self.delegate thumbnailViewController:self pageIndex:indexPath.row];
|
|
[self.delegate thumbnailViewController:self pageIndex:indexPath.row];
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ [self dismissViewControllerAnimated:YES completion:^{
|
|
|
|
+
|
|
|
|
+ }];
|
|
}
|
|
}
|
|
|
|
|
|
@end
|
|
@end
|