|
@@ -39,6 +39,8 @@
|
|
|
|
|
|
@property (nonatomic, strong) UIView *headerView;
|
|
|
|
|
|
+@property (nonatomic, assign) BOOL isPageEdit;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation CPDFPageEditViewController
|
|
@@ -70,14 +72,28 @@
|
|
|
self.isEdit = NO;
|
|
|
|
|
|
[self.collectionView registerClass:[CPDFPageEditViewCell class] forCellWithReuseIdentifier:@"pageEditCell"];
|
|
|
- self.collectionView.allowsMultipleSelection = YES;
|
|
|
self.collectionView.userInteractionEnabled = YES;
|
|
|
self.collectionView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
|
|
|
+
|
|
|
+ self.doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ [self.doneBtn setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
|
|
|
+ [self.doneBtn addTarget:self action:@selector(buttonItemClicked_done:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [self.doneBtn setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
|
|
|
+ [self.headerView addSubview:self.doneBtn];
|
|
|
+
|
|
|
+ self.selectAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ [self.selectAllBtn setImage:[UIImage imageNamed:@"CPDFPageEitImageSelectAll" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
+ [self.selectAllBtn addTarget:self action:@selector(buttonItemClicked_selectAll:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [self.headerView addSubview:self.selectAllBtn];
|
|
|
|
|
|
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognized:)];
|
|
|
[self.collectionView addGestureRecognizer:longPress];
|
|
|
|
|
|
self.view.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
|
|
|
+ self.pageEditToolBar.hidden = YES;
|
|
|
+ self.doneBtn.hidden = YES;
|
|
|
+ self.selectAllBtn.hidden = YES;
|
|
|
+ self.isPageEdit = NO;
|
|
|
}
|
|
|
|
|
|
- (void)viewWillLayoutSubviews {
|
|
@@ -87,9 +103,9 @@
|
|
|
self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, self.view.safeAreaInsets.top, 120, 50);
|
|
|
self.collectionView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 60, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - 110 - self.view.safeAreaInsets.top);
|
|
|
self.backBtn.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top, 50, 50);
|
|
|
- self.editBtn.frame = CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 50, self.view.safeAreaInsets.top, 50, 50);
|
|
|
- self.doneBtn.frame = CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 50, self.view.safeAreaInsets.top, 50, 50);
|
|
|
- self.selectAllBtn.frame = CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 110, self.view.safeAreaInsets.top, 50, 50);
|
|
|
+ self.editBtn.frame = CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 70, self.view.safeAreaInsets.top, 50, 50);
|
|
|
+ self.doneBtn.frame = CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 70, self.view.safeAreaInsets.top, 50, 50);
|
|
|
+ self.selectAllBtn.frame = CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 130, self.view.safeAreaInsets.top, 50, 50);
|
|
|
} else {
|
|
|
self.headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, 120);
|
|
|
self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 65, 120, 50);
|
|
@@ -104,10 +120,10 @@
|
|
|
#pragma mark - Action
|
|
|
|
|
|
- (void)buttonItemClicked_edit:(UIButton *)button {
|
|
|
- self.isEdit = !self.isEdit;
|
|
|
+ self.isEdit = YES;
|
|
|
self.editBtn.hidden = YES;
|
|
|
self.isSelecAll = NO;
|
|
|
-
|
|
|
+
|
|
|
CGFloat height = 44.0;
|
|
|
if (@available(iOS 11.0, *))
|
|
|
height += self.view.safeAreaInsets.bottom;
|
|
@@ -116,27 +132,48 @@
|
|
|
self.pageEditToolBar.pdfView = self.pdfView;
|
|
|
self.pageEditToolBar.currentPageIndex = -1;
|
|
|
self.pageEditToolBar.delegate = self;
|
|
|
+ self.pageEditToolBar.currentPageIndex = 1;
|
|
|
[self.view addSubview:self.pageEditToolBar];
|
|
|
-
|
|
|
- self.doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
- [self.doneBtn setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
|
|
|
- [self.doneBtn addTarget:self action:@selector(buttonItemClicked_done:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
- [self.doneBtn setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
|
|
|
- [self.headerView addSubview:self.doneBtn];
|
|
|
|
|
|
- self.selectAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
- [self.selectAllBtn setImage:[UIImage imageNamed:@"CPDFPageEitImageSelectNoAll" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
- [self.selectAllBtn addTarget:self action:@selector(buttonItemClicked_selectAll:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
- [self.headerView addSubview:self.selectAllBtn];
|
|
|
+ self.pageEditToolBar.hidden = NO;
|
|
|
+ self.doneBtn.hidden = NO;
|
|
|
+ self.selectAllBtn.hidden = NO;
|
|
|
+
|
|
|
+ if (self.isEdit) {
|
|
|
+ self.collectionView.allowsMultipleSelection = YES;
|
|
|
+ } else {
|
|
|
+ self.collectionView.allowsMultipleSelection = NO;
|
|
|
+ }
|
|
|
|
|
|
[self.collectionView reloadData];
|
|
|
+ NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.pdfView.currentPageIndex inSection:0];
|
|
|
+ [self.collectionView selectItemAtIndexPath:indexPath
|
|
|
+ animated:NO
|
|
|
+ scrollPosition:UICollectionViewScrollPositionCenteredVertically];
|
|
|
+ [self updateTitle];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- (void)buttonItemClicked_done:(UIButton *)button {
|
|
|
+ self.isEdit = NO;
|
|
|
+ self.editBtn.hidden = NO;
|
|
|
+
|
|
|
+ self.pageEditToolBar.hidden = YES;
|
|
|
+ self.doneBtn.hidden = YES;
|
|
|
+ self.selectAllBtn.hidden = YES;
|
|
|
+
|
|
|
+ [self.collectionView reloadData];
|
|
|
+
|
|
|
+ [self updateTitle];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)buttonItemClicked_back:(UIButton *)button {
|
|
|
[self dismissViewControllerAnimated:YES completion:^{
|
|
|
- [self.pdfView.document writeToURL:self.pdfView.document.documentURL];
|
|
|
- if (self.pageEditDelegate && [self.pageEditDelegate respondsToSelector:@selector(pageEditViewControllerDone:)]) {
|
|
|
- [self.pageEditDelegate pageEditViewControllerDone:self];
|
|
|
+ if (self.isPageEdit) {
|
|
|
+ [self.pdfView.document writeToURL:self.pdfView.document.documentURL];
|
|
|
+ if (self.pageEditDelegate && [self.pageEditDelegate respondsToSelector:@selector(pageEditViewControllerDone:)]) {
|
|
|
+ [self.pageEditDelegate pageEditViewControllerDone:self];
|
|
|
+ }
|
|
|
}
|
|
|
}];
|
|
|
}
|
|
@@ -144,9 +181,9 @@
|
|
|
- (void)buttonItemClicked_selectAll:(UIButton *)button {
|
|
|
self.isSelecAll = !self.isSelecAll;
|
|
|
if (self.isSelecAll) {
|
|
|
- [self.selectAllBtn setImage:[UIImage imageNamed:@"CPDFPageEitImageSelectAll" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
- } else {
|
|
|
[self.selectAllBtn setImage:[UIImage imageNamed:@"CPDFPageEitImageSelectNoAll" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
+ } else {
|
|
|
+ [self.selectAllBtn setImage:[UIImage imageNamed:@"CPDFPageEitImageSelectAll" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
}
|
|
|
|
|
|
if (self.isSelecAll) {
|
|
@@ -173,6 +210,7 @@
|
|
|
if (self.isEdit) {
|
|
|
NSInteger count = [self.collectionView indexPathsForSelectedItems].count;
|
|
|
self.titleLabel.text = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Selected:", nil), (long)count];
|
|
|
+ self.pageEditToolBar.isSelect = [self getIsSelect];
|
|
|
} else {
|
|
|
self.titleLabel.text = NSLocalizedString(@"Page Edit", nil);
|
|
|
}
|
|
@@ -200,6 +238,14 @@
|
|
|
return max+1;
|
|
|
}
|
|
|
|
|
|
+- (BOOL)getIsSelect {
|
|
|
+ if ([self.collectionView indexPathsForSelectedItems].count > 0) {
|
|
|
+ return YES;
|
|
|
+ } else {
|
|
|
+ return NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - GestureRecognized
|
|
|
|
|
|
- (void)longPressGestureRecognized:(UILongPressGestureRecognizer *)gestureRecognizer {
|
|
@@ -246,11 +292,11 @@
|
|
|
CGSize pageSize = [self.pdfView.document pageSizeAtIndex:indexPath.item];
|
|
|
CGFloat multiple = MAX(pageSize.width / 110, pageSize.height / 173);
|
|
|
|
|
|
- cell.editing = self.isEdit;
|
|
|
cell.imageSize = CGSizeMake(pageSize.width / multiple, pageSize.height / multiple);
|
|
|
[cell setNeedsLayout];
|
|
|
cell.imageView.image = [page thumbnailOfSize:CGSizeMake(pageSize.width / multiple, pageSize.height / multiple)];
|
|
|
cell.textLabel.text = [NSString stringWithFormat:@"%@",@(indexPath.item+1)];
|
|
|
+ [cell setEdit:self.isEdit];
|
|
|
return cell;
|
|
|
}
|
|
|
|
|
@@ -261,6 +307,7 @@
|
|
|
- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath {
|
|
|
if (sourceIndexPath.item != destinationIndexPath.item) {
|
|
|
[self.pdfView.document movePageAtIndex:sourceIndexPath.item withPageAtIndex:destinationIndexPath.item];
|
|
|
+ self.isPageEdit = YES;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -271,10 +318,21 @@
|
|
|
}
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
- UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
|
|
|
- self.pageEditToolBar.currentPageIndex = indexPath.item;
|
|
|
- [self updateTitle];
|
|
|
- [cell setSelected:YES];
|
|
|
+ if (self.isEdit) {
|
|
|
+ UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
|
|
|
+ self.pageEditToolBar.currentPageIndex = indexPath.item;
|
|
|
+ self.pageEditToolBar.isSelect = [self getIsSelect];
|
|
|
+ [self updateTitle];
|
|
|
+ [cell setSelected:YES];
|
|
|
+ } else {
|
|
|
+ if([self.pageEditDelegate respondsToSelector:@selector(pageEditViewController:pageIndex:)]) {
|
|
|
+ [self.pageEditDelegate pageEditViewController:self pageIndex:indexPath.item];
|
|
|
+ }
|
|
|
+
|
|
|
+ [self dismissViewControllerAnimated:YES completion:^{
|
|
|
+
|
|
|
+ }];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
@@ -299,11 +357,26 @@
|
|
|
|
|
|
[self.pdfView.document insertPage:size atIndex:pageIndex];
|
|
|
[self.collectionView reloadData];
|
|
|
+ [self.pageEditToolBar reloadData];
|
|
|
+
|
|
|
+ [self updateTitle];
|
|
|
+ self.isPageEdit = YES;
|
|
|
+ NSIndexPath *indexPath = [NSIndexPath indexPathForItem:pageIndex inSection:0];
|
|
|
+ [self.collectionView selectItemAtIndexPath:indexPath
|
|
|
+ animated:NO
|
|
|
+ scrollPosition:UICollectionViewScrollPositionCenteredVertically];
|
|
|
}
|
|
|
|
|
|
- (void)pageEditToolBarPDFInsert:(CPageEditToolBar *)pageEditToolBar pageModel:(CBlankPageModel *)pageModel document:(nonnull CPDFDocument *)document {
|
|
|
[self.pdfView.document importPages:pageModel.indexSet fromDocument:document atIndex:pageModel.pageIndex];
|
|
|
[self.collectionView reloadData];
|
|
|
+
|
|
|
+ [pageModel.indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
+ NSIndexPath *indexPath = [NSIndexPath indexPathForItem:idx+1 inSection:0];
|
|
|
+ [self.collectionView selectItemAtIndexPath:indexPath
|
|
|
+ animated:NO
|
|
|
+ scrollPosition:UICollectionViewScrollPositionCenteredVertically];
|
|
|
+ }];
|
|
|
}
|
|
|
|
|
|
- (void)pageEditToolBarExtract:(CPageEditToolBar *)pageEditToolBar {
|
|
@@ -329,6 +402,9 @@
|
|
|
[alert addAction:cancelAction];
|
|
|
[self presentViewController:alert animated:YES completion:nil];
|
|
|
[self.pageEditToolBar reloadData];
|
|
|
+
|
|
|
+ self.isPageEdit = YES;
|
|
|
+ [self updateTitle];
|
|
|
}
|
|
|
|
|
|
- (void)pageEditToolBarRotate:(CPageEditToolBar *)pageEditToolBar {
|
|
@@ -340,8 +416,16 @@
|
|
|
|
|
|
CPDFPage *pPage = [self.pdfView.document pageAtIndex:indexPath.item];
|
|
|
pPage.rotation += 90;
|
|
|
+
|
|
|
+ CGSize pageSize = [self.pdfView.document pageSizeAtIndex:indexPath.item];
|
|
|
+ CGFloat multiple = MAX(pageSize.width / 110, pageSize.height / 173);
|
|
|
+
|
|
|
+ cell.imageSize = CGSizeMake(pageSize.width / multiple, pageSize.height / multiple);
|
|
|
+ [cell setNeedsLayout];
|
|
|
}
|
|
|
- [self.pageEditToolBar reloadData];
|
|
|
+
|
|
|
+ [self updateTitle];
|
|
|
+ self.isPageEdit = YES;
|
|
|
}
|
|
|
|
|
|
- (void)pageEditToolBarDelete:(CPageEditToolBar *)pageEditToolBar {
|
|
@@ -365,8 +449,10 @@
|
|
|
}
|
|
|
[self.collectionView deleteItemsAtIndexPaths:[self.collectionView indexPathsForSelectedItems]];
|
|
|
[self.pdfView.document removePageAtIndexSet:indexSet];
|
|
|
- [self.collectionView reloadData];
|
|
|
[self.pageEditToolBar reloadData];
|
|
|
+
|
|
|
+ [self updateTitle];
|
|
|
+ self.isPageEdit = YES;
|
|
|
}
|
|
|
|
|
|
- (void)pageEditToolBarReplace:(CPageEditToolBar *)pageEditToolBar document:(CPDFDocument *)document {
|
|
@@ -388,6 +474,7 @@
|
|
|
[self.pageEditToolBar reloadData];
|
|
|
|
|
|
[self updateTitle];
|
|
|
+ self.isPageEdit = YES;
|
|
|
}
|
|
|
|
|
|
- (void)pageEditToolBarCopy:(CPageEditToolBar *)pageEditToolBar {
|
|
@@ -402,6 +489,7 @@
|
|
|
[self.pageEditToolBar reloadData];
|
|
|
|
|
|
[self updateTitle];
|
|
|
+ self.isPageEdit = YES;
|
|
|
}
|
|
|
|
|
|
@end
|