Pārlūkot izejas kodu

PDFViewer(iOS) - 导航栏颜色设置

dinglingui 1 gadu atpakaļ
vecāks
revīzija
79a7d575ee

+ 1 - 1
compdfkit-tools/compdfkit-tools/Viewer/PDFThumbnail/CPDFThumbnailViewController.m

@@ -44,7 +44,7 @@
     [self changeleftItem];
     UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
     layout.itemSize = CGSizeMake(110, 185);
-    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
+    layout.sectionInset = UIEdgeInsetsMake(10, 5, 5, 5);
     layout.minimumInteritemSpacing = 5;
     layout.minimumLineSpacing = 5;
     

+ 2 - 7
viewer-ctrl-demo/viewer-ctrl-demo/AppDelegate.m

@@ -63,13 +63,8 @@ static AppDelegate *appDelegate = NULL;
     self.window = window;
     self.window.backgroundColor = [UIColor whiteColor];
     
-    NSString *tBundleFilePath = [[NSBundle mainBundle] pathForResource:@"PDF32000_2008" ofType:@"pdf"];
-    
-    NSString *docsFolder = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
-    NSString * filePath = [docsFolder stringByAppendingPathComponent:tBundleFilePath.lastPathComponent];
-    
-    [[NSFileManager defaultManager] copyItemAtPath:tBundleFilePath toPath:filePath error:nil];
-    
+    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"PDF32000_2008" ofType:@"pdf"];
+        
     CPDFViewController *pdfViewController = [[CPDFViewController alloc] initWithFilePath:filePath];
     CNavigationController *navController = [[CNavigationController alloc]initWithRootViewController:pdfViewController];
 

+ 37 - 33
viewer-ctrl-demo/viewer-ctrl-demo/CPDFViewController.m

@@ -52,9 +52,14 @@
     
     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;
+//    self.pdfListView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     [self.view addSubview:self.pdfListView];
     
     UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"CPDFThunbnailImageEnter" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] style:UIBarButtonItemStylePlain target:self action:@selector(buttonItemClicked_thumbnail:)];
@@ -106,16 +111,22 @@
     [super viewWillLayoutSubviews];
     
     if (@available(iOS 11.0, *)) {
-        [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 250, self.view.safeAreaInsets.top - 10, 250, 200)];
+        [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 250, CGRectGetMaxY(self.navigationController.navigationBar.frame), 250, 200)];
     } else {
         // Fallback on earlier versions
-        [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - 250, -10, 250, 200)];
+        [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - 250, CGRectGetMaxY(self.navigationController.navigationBar.frame), 250, 200)];
+    }
+    
+    CGFloat tPosY = 0;
+    if (!self.navigationController.navigationBarHidden) {
+        CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
+        tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
     }
     
     if (@available(iOS 11.0, *)) {
-        self.pdfListView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top, 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);
+        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);
     } else {
-        self.pdfListView.frame = self.view.bounds;
+        self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height - tPosY);
     }
 }
 
@@ -191,11 +202,12 @@
     menuView.delegate = self;
     self.popMenu = [CPDFPopMenu popMenuWithContentView:menuView];
     self.popMenu.dimCoverLayer = YES;
+    
     if (@available(iOS 11.0, *)) {
-        [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 250, self.view.safeAreaInsets.top - 10, 250, 200)];
+        [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 250, CGRectGetMaxY(self.navigationController.navigationBar.frame), 250, 200)];
     } else {
         // Fallback on earlier versions
-        [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - 250, -10, 250, 200)];
+        [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - 250, CGRectGetMaxY(self.navigationController.navigationBar.frame), 250, 200)];
     }
 }
 
@@ -225,34 +237,26 @@
 #pragma mark - CPDFListViewDelegate
 
 - (void)PDFListViewPerformTouchEnded:(CPDFListView *)pdfView {
-    if (CPDFViewAnnotationModeNone != self.pdfListView.annotationMode) {
-        self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
-        return;
+    CGFloat tPosY = 0;
+    if (self.navigationController.navigationBarHidden) {
+        [self.navigationController setNavigationBarHidden:NO animated:YES];
+        [UIView animateWithDuration:0.3 animations:^{
+            self.pdfListView.pageSliderView.alpha = 1.0;
+        }];
+        CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
+        tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
+
+    } else {
+        [self.navigationController setNavigationBarHidden:YES animated:YES];
+        [UIView animateWithDuration:0.3 animations:^{
+            self.pdfListView.pageSliderView.alpha = 0.0;
+        }];
     }
-    if (UIUserInterfaceIdiomPhone == UI_USER_INTERFACE_IDIOM()) {
-        if (self.navigationController.navigationBarHidden) {
-            [self.navigationController setNavigationBarHidden:NO animated:YES];
-            [UIView animateWithDuration:0.3 animations:^{
-                self.pdfListView.pageSliderView.alpha = 1.0;
-            }];
-        } else {
-            [self.navigationController setNavigationBarHidden:YES animated:YES];
-            [UIView animateWithDuration:0.3 animations:^{
-                self.pdfListView.pageSliderView.alpha = 0.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);
     } else {
-        if (self.navigationController.navigationBarHidden) {
-            [self.navigationController setNavigationBarHidden:NO animated:YES];
-            [UIView animateWithDuration:0.3 animations:^{
-                self.pdfListView.pageSliderView.alpha = 1.0;
-            }];
-        } else {
-            [self.navigationController setNavigationBarHidden:YES animated:YES];
-            [UIView animateWithDuration:0.3 animations:^{
-                self.pdfListView.pageSliderView.alpha = 0.0;
-            }];
-        }
+        self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height - tPosY);
     }
 }