瀏覽代碼

Merge branch 'compdfkit_demo_ios' of git.kdan.cc:others/kmpdfkit_demo into compdfkit_demo_ios

chenyu 1 年之前
父節點
當前提交
34c3aa859a

+ 5 - 5
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Annotation.m

@@ -247,7 +247,7 @@
     } else if (CPDFAnnotationDraggingNone == self.draggingType) {
         if (self.activeAnnotation) {
             CPDFPage *previousPage = self.activeAnnotation.page;
-            self.activeAnnotation = nil;
+            [self updateActiveAnnotations:@[]];
             [self setNeedsDisplayForPage:previousPage];
             [self updateScrollEnabled];
         } else {
@@ -282,7 +282,7 @@
                         [super touchEndedAtPoint:point forPage:page];
                     }
                 } else {
-                    self.activeAnnotation = annotation;
+                    [self updateActiveAnnotations:@[annotation]];
                     [self setNeedsDisplayForPage:page];
                     [self updateScrollEnabled];
                     
@@ -298,7 +298,7 @@
                 if (CGRectIsEmpty(self.addLinkRect)) {
                     CPDFAnnotation *annotation = [page annotationAtPoint:point];
                     if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
-                        self.activeAnnotation = annotation;
+                        [self updateActiveAnnotations:@[annotation]];
                         [self setNeedsDisplayForPage:page];
                         [self updateScrollEnabled];
 
@@ -823,7 +823,7 @@
     } else if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
         [self setNeedsDisplayForPage:page];
     } else {
-        self.activeAnnotation = annotation;
+        [self updateActiveAnnotations:@[annotation]];
         [self setNeedsDisplayForPage:page];
         [self updateScrollEnabled];
         
@@ -839,7 +839,7 @@
     [annotation setUserName:[self annotationUserName]];
     [page addAnnotation:annotation];
     
-    self.activeAnnotation = annotation;
+    [self updateActiveAnnotations:@[annotation]];
     [self setNeedsDisplayForPage:page];
     [self updateScrollEnabled];
     

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

@@ -49,7 +49,9 @@ typedef NS_ENUM(NSInteger, CPDFAnnotationDraggingType) {
 
 @property (nonatomic, strong) CPDFAnnotation *menuAnnotation;
 
-@property (nonatomic, strong) CPDFAnnotation *activeAnnotation;
+@property (nonatomic, strong) NSMutableArray <CPDFAnnotation *>*activeAnnotations;
+
+@property (nonatomic, readonly) CPDFAnnotation *activeAnnotation;
 
 @property (nonatomic, assign) CGPoint menuPoint;
 
@@ -59,4 +61,6 @@ typedef NS_ENUM(NSInteger, CPDFAnnotationDraggingType) {
 
 - (NSString *)annotationUserName;
 
+- (void)updateActiveAnnotations:(NSArray <CPDFAnnotation *> *)activeAnnotations;
+
 @end

+ 4 - 10
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView.h

@@ -57,11 +57,11 @@ extern NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification;
 
 - (NSArray<UIMenuItem *> *)PDFListView:(CPDFListView *)pdfListView customizeMenuForPage:(CPDFPage *)page forPagePoint:(CGPoint)pagePoint;
 
-- (void)PDFViewPerformOpenNote:(CPDFListView *)pdfView forAnnotation:(CPDFAnnotation *)annotation;
+- (void)PDFListViewPerformOpenNote:(CPDFListView *)pdfListView forAnnotation:(CPDFAnnotation *)annotation;
 
-- (void)PDFViewPerformTouchEnded:(CPDFListView *)pdfView;
+- (void)PDFListViewPerformTouchEnded:(CPDFListView *)pdfListView;
 
-- (void)PDFViewCustomMenuClick:(CPDFListView *)pdfView identifier:(NSString *)menuIdentifier;
+- (void)PDFListViewCustomMenuClick:(CPDFListView *)pdfListView identifier:(NSString *)menuIdentifier;
 
 - (void)PDFListViewChangedToolMode:(CPDFListView *)pdfListView forToolMode:(CToolModel)toolMode;
 
@@ -84,13 +84,7 @@ extern NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification;
 
 @property (nonatomic, assign) CPDFViewAnnotationMode annotationMode;
 
-//@property (nullable, nonatomic, strong) CPDFAnnotation *activeAnnotation;
-//
-//@property (nonatomic, strong) CPDFAnnotation *addAnnotation;
-
-//@property (nonatomic, readonly) CGPoint menuPoint;
-//
-//@property (nonatomic, readonly) CPDFPage *menuPage;
+@property (nonatomic, readonly) NSMutableArray <CPDFAnnotation *>*activeAnnotations;
 
 @end
 

+ 65 - 6
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView.m

@@ -58,6 +58,8 @@ NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification = @"CPD
     return self;
 }
 
+#pragma mark - Accessors
+
 - (void)setAnnotationMode:(CPDFViewAnnotationMode)annotationMode {
     _annotationMode = annotationMode;
     
@@ -88,17 +90,40 @@ NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification = @"CPD
     
     if (CPDFViewAnnotationModeNone != annotationMode) {
         CPDFPage *page = self.activeAnnotation.page;
-        self.activeAnnotation = nil;
+        [self updateActiveAnnotations:@[]];
         [self setNeedsDisplayForPage:page];
     }
+    
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewActiveAnnotationsChangeNotification object:self];
+        
+        if([self.performDelegate respondsToSelector:@selector(PDFListViewChangedAnnotationType:forAnnotationMode:)]) {
+            [self.performDelegate PDFListViewChangedAnnotationType:self forAnnotationMode:self.annotationMode];
+        }
+    });    
 }
 
-- (NSString *)annotationUserName {
-    NSString *annotationUserName = CPDFKitShareConfig.annotationAuthor;
-    if (!annotationUserName || [annotationUserName length] <= 0) {
-        annotationUserName = [[UIDevice currentDevice] name];
+-(void)setToolModel:(CToolModel)toolModel {
+    _toolModel = toolModel;
+    
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewToolModeChangeNotification object:self];
+        
+        if([self.performDelegate respondsToSelector:@selector(PDFListViewChangedToolMode:forToolMode:)]) {
+            [self.performDelegate PDFListViewChangedToolMode:self forToolMode:self.toolModel];
+        }
+    });
+}
+
+- (NSMutableArray *)activeAnnotations {
+    if(!_activeAnnotations) {
+        _activeAnnotations = [[NSMutableArray alloc] init];
     }
-    return annotationUserName ? : @"";
+    return _activeAnnotations;
+}
+
+- (CPDFAnnotation *)activeAnnotation {
+    return self.activeAnnotations.firstObject;
 }
 
 #pragma mark - Touch
@@ -219,6 +244,40 @@ NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification = @"CPD
     [self.pageIndicatorView updatePageCount:weakSelf.document.pageCount currentPageIndex:self.currentPageIndex + 1];
 }
 
+
+- (NSString *)annotationUserName {
+    NSString *annotationUserName = CPDFKitShareConfig.annotationAuthor;
+    if (!annotationUserName || [annotationUserName length] <= 0) {
+        annotationUserName = [[UIDevice currentDevice] name];
+    }
+    return annotationUserName ? : @"";
+}
+
+- (void)updateActiveAnnotations:(NSArray <CPDFAnnotation *> *)activeAnnotations {
+    if(activeAnnotations) {
+        self.activeAnnotations = [NSMutableArray arrayWithArray:activeAnnotations];
+                    
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewActiveAnnotationsChangeNotification object:self];
+            
+            if([self.performDelegate respondsToSelector:@selector(PDFListViewChangeatioActiveAnnotations:forActiveAnnotations:)]) {
+                [self.performDelegate PDFListViewChangeatioActiveAnnotations:self forActiveAnnotations:self.activeAnnotations];
+            }
+        });
+
+    } else if (!activeAnnotations && self.activeAnnotations.count > 0) {
+        [self.activeAnnotations removeAllObjects];
+        
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewActiveAnnotationsChangeNotification object:self];
+            
+            if([self.performDelegate respondsToSelector:@selector(PDFListViewChangeatioActiveAnnotations:forActiveAnnotations:)]) {
+                [self.performDelegate PDFListViewChangeatioActiveAnnotations:self forActiveAnnotations:self.activeAnnotations];
+            }
+        });
+    }
+}
+
 #pragma mark - NotificationCenter
 
 - (void)documentChangedNotification:(NSNotification *)notification {