瀏覽代碼

PDFAnnotation(iOS) - 注释bar显示刷新问题

dinglingui 1 年之前
父節點
當前提交
e3c067699d

+ 2 - 1
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.h

@@ -60,9 +60,10 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic, strong) CPDFInkTopToolBar *topToolBar;
 
+- (instancetype)initAnnotationManage:(CAnnotationManage *)annotationManage;
+
 - (void)reloadData;
 
-- (instancetype)initAnnotationManage:(CAnnotationManage *)annotationManage;
 
 @end
 

+ 46 - 74
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.m

@@ -92,12 +92,24 @@
 #pragma mark - Public Methods
 
 - (void)reloadData {
-    if (self.selectedIndex >=0 &&
-        self.selectedIndex < self.annotationBtns.count) {
-        UIButton *selectedButton = [self.annotationBtns objectAtIndex:self.selectedIndex];
-        selectedButton.backgroundColor = [UIColor clearColor];
+    if(CPDFViewAnnotationModeNone == self.pdfListView.annotationMode) {
+        if (self.selectedIndex >=0 &&
+            self.selectedIndex < self.annotationBtns.count) {
+            UIButton *selectedButton = [self.annotationBtns objectAtIndex:self.selectedIndex];
+            selectedButton.backgroundColor = [UIColor clearColor];
+        }
+        self.selectedIndex = -1;
+    } else {
+        for (NSInteger i = 0; i< self.annotationBtns.count; i++) {
+            UIButton *button = [self.annotationBtns objectAtIndex:i];
+            if(button.tag == self.pdfListView.annotationMode) {
+                button.backgroundColor = [UIColor colorWithRed:178.0/255.0 green:239.0/255.0 blue:253.0/255.0 alpha:1.0];
+                self.selectedIndex = button.tag;
+            } else {
+                button.backgroundColor = [UIColor clearColor];
+            }
+        }
     }
-    self.selectedIndex = -1;
 }
 
 #pragma mark - Private Methods
@@ -126,23 +138,39 @@
                         @"CPDFAnnotationBarImageLink",
                         @"CPDFAnnotationBarImageSound"];
     
+    NSArray *types = @[@(CPDFViewAnnotationModeNote),
+                       @(CPDFViewAnnotationModeHighlight),
+                       @(CPDFViewAnnotationModeUnderline),
+                       @(CPDFViewAnnotationModeStrikeout),
+                       @(CPDFViewAnnotationModeSquiggly),
+                       @(CPDFViewAnnotationModeInk),
+                       @(CPDFViewAnnotationModeCircle),
+                       @(CPDFViewAnnotationModeSquare),
+                       @(CPDFViewAnnotationModeArrow),
+                       @(CPDFViewAnnotationModeLine),
+                       @(CPDFViewAnnotationModeFreeText),
+                       @(CPDFViewAnnotationModeSignature),
+                       @(CPDFViewAnnotationModeStamp),
+                       @(CPDFViewAnnotationModeImage),
+                       @(CPDFViewAnnotationModeLink),
+                       @(CPDFViewAnnotationModeSound)];
+    
     NSMutableArray *annotationBtns = [NSMutableArray array];
-    for (int i = 0; i < images.count; i++) {
+    for (int i = 0; i < types.count; i++) {
+        CPDFViewAnnotationMode annotationMode = (CPDFViewAnnotationMode)[types[i] integerValue];
         CPDFAnnotationBarButton *button = [CPDFAnnotationBarButton buttonWithType:UIButtonTypeCustom];
         button.frame = CGRectMake(offsetX, 1, 58, 43);
         [button setImage:[UIImage imageNamed:images[i] inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
-        button.tag = i;
-        button.type = i;
-        if (i == 1) {
+        button.tag = annotationMode;
+        if (CPDFViewAnnotationModeHighlight == annotationMode) {
             button.lineColor = CPDFKitShareConfig.highlightAnnotationColor;
-        } else if (i == 2) {
+        } else if (CPDFViewAnnotationModeUnderline == annotationMode) {
             button.lineColor = CPDFKitShareConfig.underlineAnnotationColor;
-        } else if (i == 3) {
+        } else if (CPDFViewAnnotationModeStrikeout == annotationMode) {
             button.lineColor = CPDFKitShareConfig.strikeoutAnnotationColor;
-        } else if (i == 4) {
+        } else if (CPDFViewAnnotationModeSquiggly == annotationMode) {
             button.lineColor = CPDFKitShareConfig.squigglyAnnotationColor;
-        } else if (i == 5) {
-            button.type = 4;
+        } else if (CPDFViewAnnotationModeInk== annotationMode) {
             button.lineColor = CPDFKitShareConfig.freehandAnnotationColor;
         }
         [button addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
@@ -191,7 +219,7 @@
 - (void)buttonItemClicked_Switch:(UIButton *)button {
     self.propertiesBtn.userInteractionEnabled = YES;
     self.propertiesBtn.tag = button.tag;
-    if (self.selectedIndex >= 0 && self.selectedIndex < self.annotationBtns.count) {
+    if (self.selectedIndex >= 0 && self.selectedIndex <= self.annotationBtns.count) {
         UIButton *selectButton = [self.annotationBtns objectAtIndex:self.selectedIndex];
         selectButton.backgroundColor = [UIColor clearColor];
     }
@@ -199,68 +227,12 @@
     if (button.tag != self.selectedIndex) {
         button.backgroundColor = [UIColor colorWithRed:178.0/255.0 green:239.0/255.0 blue:253.0/255.0 alpha:1.0];
         self.selectedIndex = button.tag;
+        self.pdfListView.annotationMode = self.selectedIndex;
+
     } else {
+        self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
         self.selectedIndex = -1;
     }
-    
-    switch (self.selectedIndex) {
-        case CPDFToolbarNote:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeNote;
-        }
-            break;
-        case CPDFToolbarHighlight:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeHighlight;
-        }
-            break;
-        case CPDFToolbarUnderline:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeUnderline;
-        }
-            break;
-        case CPDFToolbarStrikeout:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeStrikeout;
-        }
-            break;
-        case CPDFToolbarSquiggly:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeSquiggly;
-        }
-            break;
-        case CPDFToolbarFreehand:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeInk;
-        }
-            break;
-        case CPDFToolbarShapeCircle:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeCircle;
-        }
-            break;
-        case CPDFToolbarShapeRectangle:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeSquare;
-        }
-            break;
-        case CPDFToolbarShapeArrow:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeArrow;
-        }
-            break;
-        case CPDFToolbarShapeLine:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeLine;
-        }
-            break;
-            
-        default:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
-        }
-            break;
-    }
 }
 
 - (void)buttonItemClicked_open:(UIButton *)button {

+ 6 - 3
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBarButton.h

@@ -2,7 +2,12 @@
 //  CPDFAnnotationBarButton.h
 //  compdfkit-tools
 //
-//  Created by kdanmobile_2 on 2023/4/21.
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
 //
 
 #import <UIKit/UIKit.h>
@@ -11,8 +16,6 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface CPDFAnnotationBarButton : UIButton
 
-@property (nonatomic, assign) NSInteger type;
-
 @property (nonatomic, strong) UIColor *lineColor;
 
 @end

+ 11 - 5
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBarButton.m

@@ -2,10 +2,16 @@
 //  CPDFAnnotationBarButton.m
 //  compdfkit-tools
 //
-//  Created by kdanmobile_2 on 2023/4/21.
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
 //
 
 #import "CPDFAnnotationBarButton.h"
+#import "CPDFListView.h"
 
 @implementation CPDFAnnotationBarButton
 
@@ -14,19 +20,19 @@
     CGRect imageFrame = self.imageView.frame;
     CGContextRef ctx = UIGraphicsGetCurrentContext();
     CGContextSetStrokeColorWithColor(ctx, self.lineColor.CGColor);
-    if (self.type == 1) {
+    if (self.tag == CPDFViewAnnotationModeHighlight) {
         CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame)-2, CGRectGetMidY(imageFrame));
         CGContextSetLineWidth(ctx, CGRectGetHeight(imageFrame));
         CGContextAddLineToPoint(ctx, CGRectGetMaxX(imageFrame)+2, CGRectGetMidY(imageFrame));
-    }else if (self.type == 2) {
+    }else if (self.tag == CPDFViewAnnotationModeUnderline) {
         CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame), CGRectGetMaxY(imageFrame));
         CGContextSetLineWidth(ctx, 2.0);
         CGContextAddLineToPoint(ctx, CGRectGetMaxX(imageFrame), CGRectGetMaxY(imageFrame));
-    } else if (self.type == 3) {
+    } else if (self.tag == CPDFViewAnnotationModeStrikeout) {
         CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame), CGRectGetMidY(imageFrame));
         CGContextSetLineWidth(ctx, 2.0);
         CGContextAddLineToPoint(ctx, CGRectGetMaxX(imageFrame), CGRectGetMidY(imageFrame));
-    } else if (self.type == 4) {
+    } else if (self.tag == CPDFViewAnnotationModeSquiggly) {
         float tWidth = imageFrame.size.width / 6.0;
         CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame), CGRectGetMaxY(imageFrame));
         CGContextSetLineWidth(ctx, 2.0);

+ 1 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView.h

@@ -34,6 +34,7 @@ typedef NS_ENUM(NSInteger, CPDFViewAnnotationMode) {
     CPDFViewAnnotationModeLine,
     CPDFViewAnnotationModeInk,
     CPDFViewAnnotationModeFreeText,
+    CPDFViewAnnotationModeSignature,
     CPDFViewAnnotationModeStamp,
     CPDFViewAnnotationModeImage,
     CPDFViewAnnotationModeLink,