Преглед на файлове

PDFTools(iOS)- 预览模块bug修复

chenyu преди 1 година
родител
ревизия
29ad25819d

+ 3 - 2
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView.m

@@ -229,6 +229,7 @@ NSNotificationName const CPDFListViewAnnotationsOperationChangeNotification = @"
     _pageSliderView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin;
     [self addSubview:self.pageSliderView];
     
+    
     _pageIndicatorView = [[CPDFPageIndicatorView alloc] init];
     
     __weak typeof(self) weakSelf = self;
@@ -246,9 +247,9 @@ NSNotificationName const CPDFListViewAnnotationsOperationChangeNotification = @"
             NSInteger pageIndex = [pageTextField.text integerValue] - 1;
             
             if (pageIndex > weakSelf.document.pageCount){
-                pageIndex = weakSelf.document.pageCount;
+                pageIndex = weakSelf.document.pageCount - 1;
             } else if(pageIndex<0){
-                pageIndex = 0;
+                pageIndex = weakSelf.document.pageCount - 1;
             } else  if(pageTextField.text.length == 0){
                 pageIndex = (int)weakSelf.currentPageIndex;
             }

+ 0 - 3
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFSliderView/CPDFSlider.m

@@ -47,7 +47,6 @@
         _label.backgroundColor = [UIColor blackColor];
         _label.layer.cornerRadius = 2.0;
         _label.layer.borderWidth = 1.0;
-//        _label.layer.borderColor = [UIColor lightGrayColor].CGColor;
         _label.hidden = YES;
     }
     return _label;
@@ -70,7 +69,6 @@
         self.label.layer.cornerRadius = 2.0;
         self.label.layer.borderWidth = 1.0;
         self.label.font = [UIFont systemFontOfSize:12.0];
-//        self.label.layer.borderColor = [UIColor lightGrayColor].CGColor;
         self.label.hidden = YES;
         
         [self addSubview:self.label];
@@ -106,7 +104,6 @@
     pageIndex = MAX(0, pageIndex);
     pageIndex = MIN(pageIndex, [self.pdfView.document pageCount]-1);
     
-//    self.label.text = [NSString stringWithFormat:@"%@/%@",@(pageIndex+1),@([self.pdfView.document pageCount])];
     self.label.text = [NSString stringWithFormat:@"%@",@(pageIndex+1)];
     [self.label sizeToFit];
     self.label.frame = CGRectMake(0, 0,

+ 4 - 2
compdfkit-tools/compdfkit-tools/Viewer/PDFBookmark/CPDFBookmarkViewController.m

@@ -122,8 +122,10 @@
         UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
         
         UIAlertAction *addAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Add", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-            [self.pdfView.document addBookmark:alert.textFields.firstObject.text forPageIndex:self.pdfView.currentPageIndex];
-            [self reloadData];
+            if(alert.textFields.firstObject.text.length > 0) {
+                [self.pdfView.document addBookmark:alert.textFields.firstObject.text forPageIndex:self.pdfView.currentPageIndex];
+                [self reloadData];
+            }
         }];
         
         [alert addAction:cancelAction];

+ 4 - 1
compdfkit-tools/compdfkit-tools/Viewer/PDFOutlie/CPDFOutlineViewCell.m

@@ -28,6 +28,7 @@
         _nameLabel = nameLabel;
         _nameLabel.font = [UIFont systemFontOfSize:14.];
         UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.bounds.size.width-55, 0, 50, 16)];
+        
         countLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
         _countLabel = countLabel;
         _countLabel.font = [UIFont systemFontOfSize:14.];
@@ -59,7 +60,9 @@
         
     }
     
-    self.nameLabel.frame = CGRectMake(25 + 10 * outline.level,10, self.bounds.size.width - self.offsetX.constant - 120, 14);
+    self.nameLabel.frame = CGRectMake(25 + 10 * outline.level,10, self.bounds.size.width - self.offsetX.constant - 100, 14);
+    self.countLabel.frame = CGRectMake(self.bounds.size.width-55, 10, 55, 14);
+    
 }
 
 - (void)setIsShow:(BOOL)isShow {

+ 68 - 5
compdfkit-tools/compdfkit-tools/Viewer/PDFSearch/CPDFSearchResultsViewController.m

@@ -29,6 +29,9 @@
 @property (nonatomic, strong) UILabel * searchResultLabel;
 @property (nonatomic, strong) UILabel * pageLabel;
 
+@property (nonatomic, strong) UILabel *titleLabel;
+@property (nonatomic, strong) UIButton *backBtn;
+
 @end
 
 @implementation CPDFSearchResultsViewController
@@ -52,8 +55,8 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view.
-    [self changeleftItem];
-    self.title = NSLocalizedString(@"Search Results", nil);
+//    [self changeleftItem];
+//    self.title = NSLocalizedString(@"Search Results", nil);
     
     self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
     self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@@ -81,20 +84,80 @@
     [self.searchResultView addSubview:self.pageLabel];
     [self.view addSubview:self.searchResultView];
     
+    [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
+    
+    
+    self.titleLabel = [[UILabel alloc] init];
+    self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
+  
+    self.titleLabel.text =  NSLocalizedString(@"Search Results", 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)viewWillLayoutSubviews {
+//
+//    if (@available(iOS 11.0, *)) {
+//
+//        self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, 50);
+//
+//        self.tableView.frame = CGRectMake(self.view.safeAreaInsets.left, 62, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - 92);
+//        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.tableView.frame = CGRectMake(0, 62, self.view.frame.size.width, self.view.frame.size.height - 92);
+//        self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 50);
+//    }
+//
+//
+//}
+
+- (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 {
     [super viewWillLayoutSubviews];
     
     if (@available(iOS 11.0, *)) {
-        self.tableView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top +28, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - self.view.safeAreaInsets.bottom- self.view.safeAreaInsets.top - 28);
+        self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, 50);
+        self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 50);
+        self.tableView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top +28 + 50, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - self.view.safeAreaInsets.bottom- self.view.safeAreaInsets.top - 50);
+        self.searchResultView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 50, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 28);
+        self.searchResultLabel.frame = CGRectMake(70, 4, 200, 20);
+        self.searchResultLabel.text = [NSString stringWithFormat:@"%zd results found",self.resultArray.count];
+        self.pageLabel.frame = CGRectMake(self.view.frame.size.width - 50, 4, 40, 20);
+    } else {
+        self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, 50);
+        self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 50);
         self.searchResultView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 28);
         self.searchResultLabel.frame = CGRectMake(20, 4, 200, 20);
         self.searchResultLabel.text = [NSString stringWithFormat:@"%zd results found",self.resultArray.count];
         self.pageLabel.frame = CGRectMake(self.view.frame.size.width - 50, 4, 40, 20);
-    } else {
-        self.tableView.frame = self.view.bounds;
+//        self.view.bounds
+        self.tableView.frame = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y + 50 + 28, self.view.bounds.size.width, self.view.bounds.size.height - 50 - 28);
       
     }
 }

+ 13 - 1
compdfkit-tools/compdfkit-tools/Viewer/PDFSearch/CSearchToolbar.m

@@ -79,6 +79,7 @@
 }
 
 - (void)beganSearchText:(NSString *)searchText {
+    
     if (![[CPDFKit sharedInstance] allowsFeature:CPDFKitFeatureViewerSearch]) {
         UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
                                                                style:UIAlertActionStyleCancel
@@ -95,8 +96,9 @@
         return;
     }
     
-    if ([searchText length] < 1)
+    if ([searchText length] < 1){
         return;
+    }
         
  // The search for document characters cannot be repeated
     self.window.userInteractionEnabled = NO;
@@ -116,6 +118,10 @@
             [self.loadingView removeFromSuperview];
 
             block_self.resultArray = results;
+            
+            if(results.count > 0){
+                self.previousItem.hidden = self.nextListItem.hidden = self.searchListItem.hidden = NO;
+            }
 
             dispatch_async(dispatch_get_main_queue(), ^{
                 if ([block_self.resultArray count] < 1) {
@@ -211,6 +217,8 @@
     [self.searchListItem addTarget:self action:@selector(buttonItemClicked_SearchList:) forControlEvents:UIControlEventTouchUpInside];
     
     self.searchBar.delegate = self;
+    
+    self.previousItem.hidden = self.nextListItem.hidden = self.searchListItem.hidden = YES;
 }
 
 #pragma mark - Action
@@ -276,4 +284,8 @@
     [self beganSearchText:string];
 }
 
+- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
+    self.previousItem.hidden = self.nextListItem.hidden = self.searchListItem.hidden = YES;
+}
+
 @end

+ 7 - 4
compdfkit-tools/compdfkit-tools/Viewer/PDFThumbnail/CPDFThumbnailViewCell.m

@@ -24,8 +24,8 @@
         _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - 12, frame.size.width, 12)];
         _textLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
         _textLabel.textAlignment = NSTextAlignmentCenter;
-        _textLabel.font = [UIFont systemFontOfSize:10];
-        _textLabel.textColor = [UIColor colorWithRed:20./255 green:96./255 blue:243./255 alpha:1];
+        _textLabel.font = [UIFont systemFontOfSize:13];
+        _textLabel.textColor = [UIColor blackColor];
         [self.contentView addSubview:_textLabel];
     }
     return self;
@@ -36,9 +36,11 @@
     
     CGFloat startW = [self.textLabel.text sizeWithFont:[UIFont systemFontOfSize:10] constrainedToSize:CGSizeMake(MAXFLOAT, 12)].width;
     //restSize
-    _textLabel.frame = CGRectMake(self.frame.size.width/2 - (startW + 10)/2, self.imageSize.height + (self.imageSize.height - 10 - self.imageSize.height) / 2, startW + 10, 12);
+    _textLabel.frame = CGRectMake(self.frame.size.width/2 - (startW + 20)/2, self.imageSize.height + (self.imageSize.height - 10 - self.imageSize.height) / 2, startW + 20, 12);
 }
 
+
+
 - (void)setPageRef:(CGPDFPageRef)pageRef {
     CGRect boxRect = CGRectZero;
     if (pageRef) {
@@ -63,8 +65,9 @@
         self.imageView.layer.cornerRadius = 4;
         self.imageView.clipsToBounds = YES;
     } else {
+        self.textLabel.backgroundColor = [UIColor clearColor];
         self.textLabel.textColor = [UIColor blackColor];
-        self.imageView.layer.borderColor = [UIColor clearColor].CGColor;
+        self.imageView.layer.borderColor = [UIColor colorWithRed:242/255. green:242/255. blue:242/255. alpha:1.].CGColor;
         self.imageView.layer.borderWidth = 1;
     }
 }

+ 73 - 4
compdfkit-tools/compdfkit-tools/Viewer/PDFThumbnail/CPDFThumbnailViewController.m

@@ -20,6 +20,10 @@
 
 @property (nonatomic, strong) UICollectionView *collectionView;
 
+@property (nonatomic, strong) UILabel *titleLabel;
+
+@property (nonatomic, strong) UIButton *backBtn;
+
 @end
 
 @implementation CPDFThumbnailViewController
@@ -40,7 +44,6 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view.
-    self.title = @"Thumbnail";
     [self changeleftItem];
     UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
     layout.itemSize = CGSizeMake(110, 185);
@@ -49,7 +52,7 @@
     layout.minimumLineSpacing = 5;
     
     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.delegate = self;
     self.collectionView.dataSource = self;
@@ -58,26 +61,87 @@
         _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 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 {
     [super viewWillAppear:animated];
     
     [self.collectionView reloadData];
+
     NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.pdfView.currentPageIndex inSection:0];
     [self.collectionView selectItemAtIndexPath:indexPath
                                       animated:NO
                                 scrollPosition:UICollectionViewScrollPositionCenteredVertically];
 }
 
+
 - (void)viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
-    
+
     NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.pdfView.currentPageIndex inSection:0];
     [self.collectionView scrollToItemAtIndexPath:indexPath
                                 atScrollPosition:UICollectionViewScrollPositionCenteredVertically
                                         animated:YES];
+
 }
 
 #pragma mark - Class method
@@ -99,7 +163,7 @@
 }
 
 - (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];
     CGSize pageSize = [self.pdfView.document pageSizeAtIndex:indexPath.item];
     CGFloat multiple = MAX(pageSize.width / 110, pageSize.height / 173);
@@ -114,9 +178,14 @@
 
 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
     
+    
     if([self.delegate respondsToSelector:@selector(thumbnailViewController:pageIndex:)]) {
         [self.delegate thumbnailViewController:self pageIndex:indexPath.row];
     }
+    
+    [self dismissViewControllerAnimated:YES completion:^{
+            
+    }];
 }
 
 @end

+ 4 - 0
viewer-ctrl-demo/viewer-ctrl-demo.xcodeproj/project.pbxproj

@@ -41,6 +41,7 @@
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
+		4F0373CF2A13802200ED4DB5 /* viewer-ctrl-demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "viewer-ctrl-demo.entitlements"; sourceTree = "<group>"; };
 		4FBCB53629E8253D00F86483 /* XPDXMLElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XPDXMLElement.h; sourceTree = "<group>"; };
 		4FBCB53729E8253D00F86483 /* XPDXMLElement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XPDXMLElement.m; sourceTree = "<group>"; };
 		4FBCB53829E8253D00F86483 /* XMLParseManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMLParseManager.m; sourceTree = "<group>"; };
@@ -99,6 +100,7 @@
 		C9413B0A29E420C700F2CBF6 /* viewer-ctrl-demo */ = {
 			isa = PBXGroup;
 			children = (
+				4F0373CF2A13802200ED4DB5 /* viewer-ctrl-demo.entitlements */,
 				C9413B0B29E420C700F2CBF6 /* AppDelegate.h */,
 				C9413B0C29E420C700F2CBF6 /* AppDelegate.m */,
 				C9413B0E29E420C700F2CBF6 /* SceneDelegate.h */,
@@ -359,6 +361,7 @@
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES;
+				CODE_SIGN_ENTITLEMENTS = "viewer-ctrl-demo/viewer-ctrl-demo.entitlements";
 				CODE_SIGN_STYLE = Automatic;
 				CURRENT_PROJECT_VERSION = 1;
 				DEVELOPMENT_TEAM = 4GGQPGRTSV;
@@ -389,6 +392,7 @@
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES;
+				CODE_SIGN_ENTITLEMENTS = "viewer-ctrl-demo/viewer-ctrl-demo.entitlements";
 				CODE_SIGN_STYLE = Automatic;
 				CURRENT_PROJECT_VERSION = 1;
 				DEVELOPMENT_TEAM = 4GGQPGRTSV;

+ 72 - 28
viewer-ctrl-demo/viewer-ctrl-demo/CPDFViewController.m

@@ -54,11 +54,6 @@
     
     self.view.backgroundColor = [CPDFColorUtils CPDFViewControllerBackgroundColor];
     self.pdfListView = [[CPDFListView alloc] initWithFrame:self.view.bounds];
-    if (@available(iOS 11.0, *)) {
-          self.pdfListView.frame = CGRectMake(self.view.safeAreaInsets.left, 0, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - self.view.safeAreaInsets.bottom);
-      } else {
-          self.pdfListView.frame = self.view.bounds;
-      }
     self.pdfListView.performDelegate = self;
     self.pdfListView.delegate = self;
     self.pdfListView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@@ -109,15 +104,24 @@
     
     
     CGFloat tPosY = 0;
+    CGFloat bottomY = 0;
+    CGFloat height = 0;
+    
+    if (@available(iOS 11.0, *))
+        height += self.view.safeAreaInsets.bottom;
+  
+    
     if (!self.navigationController.navigationBarHidden) {
         CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
         tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
+    } else {
+        bottomY = 0;
     }
     
     if (@available(iOS 11.0, *)) {
-        self.pdfListView.frame = CGRectMake(self.view.safeAreaInsets.left, tPosY, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - self.view.safeAreaInsets.bottom- tPosY);
+        self.pdfListView.frame = CGRectMake(self.view.safeAreaInsets.left, tPosY, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - tPosY- bottomY);
     } else {
-        self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height - tPosY);
+        self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height - tPosY-bottomY);
     }
 }
 
@@ -207,7 +211,11 @@
 - (void)buttonItemClicked_thumbnail:(id)sender {
     CPDFThumbnailViewController *thumbnailViewController = [[CPDFThumbnailViewController alloc] initWithPDFView:self.pdfListView];
     thumbnailViewController.delegate = self;
-    [self.navigationController pushViewController:thumbnailViewController animated:NO];
+//    [self.navigationController pushViewController:thumbnailViewController animated:NO];
+    AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
+    presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:thumbnailViewController presentingViewController:self];
+    thumbnailViewController.transitioningDelegate = presentationController;
+    [self presentViewController:thumbnailViewController animated:YES completion:nil];
 }
 
 - (void)menuItemClick_CopyAction:(id)sender {
@@ -268,11 +276,16 @@
         [self presentViewController:alert animated:YES completion:nil];
         return;
     }
-    [self searchToolbarOnExitSearch:searchToolbar];
     
     CPDFSearchResultsViewController* searchResultController = [[CPDFSearchResultsViewController alloc] initWithResultArray:results keyword:searchToolbar.searchKeyString document:self.pdfListView.document];
     searchResultController.delegate = self;
-    [self.navigationController pushViewController:searchResultController animated:YES];
+    
+    
+    AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
+    presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:searchResultController presentingViewController:self];
+    searchResultController.transitioningDelegate = presentationController;
+    [self presentViewController:searchResultController animated:YES completion:nil];
+//    [self.navigationController pushViewController:searchResultController animated:YES];
 }
 
 - (void)searchToolbarOnExitSearch:(CSearchToolbar *)searchToolbar {
@@ -407,27 +420,58 @@
 }
 
 #pragma mark - UIDocument Picker
-- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
+
+- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
     
     __weak typeof(self) weakSelf = self;
-    BOOL canAccessingResource = [url startAccessingSecurityScopedResource];
-       if(canAccessingResource) {
-           NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
-           NSError *error;
-           [fileCoordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {
-               [weakSelf reloadDocumentWithFilePath:newURL.path completion:^(BOOL result) {
-                   
-               }];
-           }];
-           if (error) {
+    //获取授权
+    BOOL fileUrlAuthozied = [urls.firstObject startAccessingSecurityScopedResource];
+    if(fileUrlAuthozied){
+        //通过文件协调工具来得到新的文件地址,以此得到文件保护功能
+        NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
+        NSError *error;
+        //读取文件
+        [fileCoordinator coordinateReadingItemAtURL:urls.firstObject options:0 error:&error byAccessor:^(NSURL *newURL) {
+            
+            NSFileManager * fileManager = [NSFileManager defaultManager];
+            NSString * appDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
+            NSString *fileName = [newURL lastPathComponent];
+            NSString * filePath = [appDir stringByAppendingPathComponent:fileName];
+            
+            if(![fileManager fileExistsAtPath:filePath]) {
+                BOOL filePresent = [weakSelf copyMissingFile:newURL.path toPath:appDir];
+                NSString * savedPath = [NSString stringWithFormat:@"%@/%@",appDir,fileName];
+                
+                [weakSelf reloadDocumentWithFilePath:savedPath completion:^(BOOL result) {
+                    [weakSelf.pdfListView reloadInputViews];
+                }];
+                
+            }
+            NSError *error = nil;
+            if (error) {
+                //
+            } else {
                
-           }
-       } else {
-           // startAccessingSecurityScopedResource fail
-       }
-       [url stopAccessingSecurityScopedResource];
-    
-    
+            }
+            
+            [self dismissViewControllerAnimated:YES completion:NULL];
+            
+        }];
+        [urls.firstObject stopAccessingSecurityScopedResource];
+        
+    }else{
+        //Error handling
+        NSLog(@"Faild");
+    }
+}
+
+- (BOOL)copyMissingFile:(NSString*)sourcePath toPath:(NSString*)toPath {
+    BOOL retVal = YES;
+    NSString * finalLocation = [toPath stringByAppendingPathComponent:[sourcePath lastPathComponent]];
+    if(![[NSFileManager defaultManager]  fileExistsAtPath:finalLocation]) {
+        retVal = [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:finalLocation error:NULL];
+    }
+    return retVal;
 }
 
 @end

+ 14 - 0
viewer-ctrl-demo/viewer-ctrl-demo/viewer-ctrl-demo.entitlements

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>com.apple.developer.icloud-container-identifiers</key>
+	<array/>
+	<key>com.apple.developer.icloud-services</key>
+	<array>
+		<string>CloudDocuments</string>
+	</array>
+	<key>com.apple.developer.ubiquity-container-identifiers</key>
+	<array/>
+</dict>
+</plist>