Преглед изворни кода

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

chenyu пре 1 година
родитељ
комит
ff79181791

+ 24 - 13
Form-Ctrl-Demo/Form-Ctrl-Demo/CPDFViewController.m

@@ -123,10 +123,14 @@
         }
     }
     
-    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 - tBottomY - tPosY);
-    } else {
-        self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height  - tBottomY - tPosY);
+    if (CPDFDisplayDirectionVertical == [CPDFKitConfig  sharedInstance].displayDirection) {
+            UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
+            inset.bottom = 10 + self.formBar.frame.size.height;
+            self.pdfListView.documentView.contentInset = inset;
+    } else{
+            UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
+            inset.bottom = 0;
+            self.pdfListView.documentView.contentInset = inset;
     }
 }
 
@@ -147,10 +151,14 @@
     tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
     tBottomY = self.formBar.frame.size.height;
     
-    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 - tBottomY - tPosY);
-    } else {
-        self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height  - tBottomY - tPosY);
+    if (CPDFDisplayDirectionVertical == [CPDFKitConfig  sharedInstance].displayDirection) {
+            UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
+            inset.bottom = 10 + self.formBar.frame.size.height;
+            self.pdfListView.documentView.contentInset = inset;
+    } else{
+            UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
+            inset.bottom = 0;
+            self.pdfListView.documentView.contentInset = inset;
     }
     [self.formBar updateStatus];
 }
@@ -249,12 +257,15 @@
         }
     }
     
-    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 - tBottomY - tPosY);
-    } else {
-        self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height  - tBottomY - tPosY);
+    if (CPDFDisplayDirectionVertical == [CPDFKitConfig  sharedInstance].displayDirection) {
+            UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
+            inset.bottom = 10 + self.formBar.frame.size.height;
+            self.pdfListView.documentView.contentInset = inset;
+    } else{
+            UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
+            inset.bottom = 0;
+            self.pdfListView.documentView.contentInset = inset;
     }
-
 }
 
 - (void)PDFListViewChangedAnnotationType:(CPDFListView *)pdfListView forAnnotationMode:(CPDFViewAnnotationMode)annotationMode {

+ 0 - 33
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFLink/CPDFLinkViewController.m

@@ -181,39 +181,6 @@
     [self updatePreferredContentSizeWithTraitCollection:newCollection];
 }
 
-- (void)viewWillDisappear:(BOOL)animated {
-    [super viewWillDisappear:animated];
-    
-    NSString *currentTextField = nil;
-
-    switch (self.segmentedControl.selectedSegmentIndex) {
-        case 0:
-            currentTextField = self.urlTextField.text;
-            break;
-        case 1:
-            currentTextField = self.pageTextField.text;
-            break;
-        default:
-        case 2:
-            currentTextField = self.emailTextField.text;
-            break;
-    }
-    
-    BOOL isLink;
-    if (!([currentTextField isEqual:@""])) {
-        isLink = YES;
-    } else {
-        isLink = NO;
-    }
-    
-    [self dismissViewControllerAnimated:YES completion:^{
-        if (self.delegate && [self.delegate respondsToSelector:@selector(linkViewControllerDismiss:isLink:)]) {
-            [self.delegate linkViewControllerDismiss:self isLink:isLink];
-        }
-    }];
-}
-
-
 - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
     
     self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 350 : 600);

+ 111 - 37
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFSignature/CPDFSignatureEditViewController.m

@@ -54,6 +54,12 @@
 
 @property (nonatomic, strong) UIView *headerView;
 
+@property (nonatomic, assign) BOOL isDrawSignature;
+
+@property (nonatomic, assign) BOOL isTexrSignature;
+
+@property (nonatomic, assign) BOOL isImageSignature;
+
 @end
 
 @implementation CPDFSignatureEditViewController
@@ -132,6 +138,7 @@
     self.saveButton = [[UIButton alloc] init];
     [self.saveButton setTitle:NSLocalizedString(@"Save", nil) forState:UIControlStateNormal];
     [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
+    self.saveButton.enabled = NO;
     [self.saveButton addTarget:self action:@selector(buttonItemClicked_Save:) forControlEvents:UIControlEventTouchUpInside];
     [self.headerView addSubview:self.saveButton];
     
@@ -139,9 +146,11 @@
     self.bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
     self.textField = [[UITextField alloc] init];
     self.textField.delegate = self;
+    self.textField.textColor = [UIColor blackColor];
     self.textField.placeholder = NSLocalizedString(@"Enter your signature", nil);
     self.textField.textAlignment = NSTextAlignmentCenter;
     self.textField.font = [UIFont systemFontOfSize:30];
+    [self.textField addTarget:self action:@selector(textTextField_change:) forControlEvents:UIControlEventEditingChanged];
     [self.view addSubview:self.textField];
     [self.textField.layer addSublayer:self.bottomBorder];
     self.textField.hidden = YES;
@@ -170,6 +179,10 @@
     self.view.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
     [self createGestureRecognizer];
     [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
+    
+    self.isImageSignature = NO;
+    self.isDrawSignature = NO;
+    self.isImageSignature = NO;
 }
 
 - (void)viewWillLayoutSubviews {
@@ -284,6 +297,75 @@
     return textFieldImage;
 }
 
+- (void)initDrawSignatureViewProperties {
+    self.colorSelectView.hidden = NO;
+    self.signatureDrawTextView.hidden = NO;
+    self.selecIndex = CSignatureTopBarDefault;
+    self.colorSelectView.hidden = NO;
+    self.clearButton.hidden = NO;
+    self.signatureDrawTextView.selectIndex = CSignatureDrawText;
+    self.emptyLabel.hidden = NO;
+    self.thicknessView.hidden = NO;
+    self.signatureDrawImageView.hidden = YES;
+    self.createButton.hidden = YES;
+    self.textField.hidden = YES;
+    [self.textField resignFirstResponder];
+    
+    if (self.isDrawSignature) {
+        [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
+        self.saveButton.enabled = YES;
+    } else {
+        [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
+        self.saveButton.enabled = NO;
+    }
+}
+
+- (void)initTextSignatureViewProperties {
+    self.colorSelectView.hidden = NO;
+    self.signatureDrawTextView.hidden = YES;
+    self.signatureDrawImageView.hidden = YES;
+    self.textField.hidden = NO;
+    self.selecIndex = CSignatureTopBarText;
+    self.colorSelectView.hidden = NO;
+    self.createButton.hidden = YES;
+    self.thicknessView.hidden = YES;
+    self.clearButton.hidden = NO;
+    self.emptyLabel.hidden = YES;
+    [self.textField becomeFirstResponder];
+    
+    if (self.isTexrSignature) {
+        [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
+        self.saveButton.enabled = YES;
+    } else {
+        [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
+        self.saveButton.enabled = NO;
+    }
+}
+
+- (void)initImageSignatureViewProperties {
+    [self.textField resignFirstResponder];
+    self.colorSelectView.hidden = YES;
+    self.signatureDrawTextView.hidden = YES;
+    self.signatureDrawImageView.hidden = NO;
+    self.textField.hidden = YES;
+    self.selecIndex = CSignatureTopBarImage;
+    self.createButton.hidden = NO;
+    self.colorSelectView.hidden = YES;
+    self.signatureDrawImageView.selectIndex = CSignatureDrawImage;
+    self.thicknessView.hidden = YES;
+    self.clearButton.hidden = YES;
+    self.emptyLabel.hidden = YES;
+    [self.signatureDrawImageView setNeedsDisplay];
+    
+    if (self.isImageSignature) {
+        [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
+        self.saveButton.enabled = YES;
+    } else {
+        [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
+        self.saveButton.enabled = NO;
+    }
+}
+
 #pragma mark - Action
 
 - (void)buttonItemClicked_Save:(id)sender {
@@ -326,44 +408,11 @@
 
 - (void)segmentedControlValueChanged_singature:(id)sender {
     if (self.segmentedControl.selectedSegmentIndex == 0) {
-        self.colorSelectView.hidden = NO;
-        self.signatureDrawTextView.hidden = NO;
-        self.selecIndex = CSignatureTopBarDefault;
-        self.colorSelectView.hidden = NO;
-        self.clearButton.hidden = NO;
-        self.signatureDrawTextView.selectIndex = CSignatureDrawText;
-        self.emptyLabel.hidden = NO;
-        self.thicknessView.hidden = NO;
-        self.signatureDrawImageView.hidden = YES;
-        self.createButton.hidden = YES;
-        self.textField.hidden = YES;
-        [self.textField resignFirstResponder];
+        [self initDrawSignatureViewProperties];
     } else if (self.segmentedControl.selectedSegmentIndex == 1) {
-        self.colorSelectView.hidden = NO;
-        self.signatureDrawTextView.hidden = YES;
-        self.signatureDrawImageView.hidden = YES;
-        self.textField.hidden = NO;
-        self.selecIndex = CSignatureTopBarText;
-        self.colorSelectView.hidden = NO;
-        self.createButton.hidden = YES;
-        self.thicknessView.hidden = YES;
-        self.clearButton.hidden = NO;
-        self.emptyLabel.hidden = YES;
-        [self.textField becomeFirstResponder];
+        [self initTextSignatureViewProperties];
     } else if (self.segmentedControl.selectedSegmentIndex == 2) {
-        [self.textField resignFirstResponder];
-        self.colorSelectView.hidden = YES;
-        self.signatureDrawTextView.hidden = YES;
-        self.signatureDrawImageView.hidden = NO;
-        self.textField.hidden = YES;
-        self.selecIndex = CSignatureTopBarImage;
-        self.createButton.hidden = NO;
-        self.colorSelectView.hidden = YES;
-        self.signatureDrawImageView.selectIndex = CSignatureDrawImage;
-        self.thicknessView.hidden = YES;
-        self.clearButton.hidden = YES;
-        self.emptyLabel.hidden = YES;
-        [self.signatureDrawImageView setNeedsDisplay];
+        [self initImageSignatureViewProperties];
     }
 }
 
@@ -376,12 +425,30 @@
     if (self.segmentedControl.selectedSegmentIndex == 0) {
         [self.signatureDrawTextView signatureClear];
         self.emptyLabel.text = NSLocalizedString(@"Signature Here", nil);
+        self.isDrawSignature = NO;
+        [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
+        self.saveButton.enabled = NO;
     } else if (self.segmentedControl.selectedSegmentIndex == 1) {
         self.textField.text = @"";
+        self.isTexrSignature = NO;
+        [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
+        self.saveButton.enabled = NO;
     }
     
 }
 
+- (void)textTextField_change:(UITextField *)textField {
+    if (self.textField.text.length > 0) {
+        self.isTexrSignature = YES;
+        [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
+        self.saveButton.enabled = YES;
+    } else {
+        self.isTexrSignature = NO;
+        [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
+        self.saveButton.enabled = NO;
+    }
+}
+
 #pragma mark - UITextFieldDelegate
 
 - (void)textFieldDidBeginEditing:(UITextField *)textField {
@@ -395,7 +462,6 @@
             self.textField.center = CGPointMake(self.textField.center.x, self.textField.center.y-100);
         } completion:nil];
     }
-    [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
 }
 
 - (void)textFieldDidEndEditing:(UITextField *)textField {
@@ -465,6 +531,12 @@
     [picker dismissViewControllerAnimated:YES completion:nil];
     UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
     
+    if (image) {
+        self.isImageSignature = YES;
+        [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
+        self.saveButton.enabled = YES;
+    }
+    
     UIImageOrientation imageOrientation = image.imageOrientation;
     if (imageOrientation!=UIImageOrientationUp) {
         UIGraphicsBeginImageContext(image.size);
@@ -536,6 +608,8 @@
 
 - (void)signatureDrawViewStart:(CSignatureDrawView *)signatureDrawView {
     [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
+    self.saveButton.enabled = YES;
+    self.isDrawSignature = YES;
     self.emptyLabel.text = @"";
 }
 

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

@@ -74,6 +74,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)buttonItemClicked_openAnnotation:(id)button;
 
+- (void)buttonItemClicked_openModel:(id)button;
+
 - (void)openSignatureAnnotation:(CPDFSignatureWidgetAnnotation *)signatureAnnotation;
 
 - (void)addStampAnnotationWithPage:(CPDFPage *)page point:(CGPoint)point;

+ 12 - 2
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.m

@@ -293,7 +293,7 @@
 - (void)updatePropertiesButtonState {
     if(CPDFViewAnnotationModeNone != self.pdfListView.annotationMode) {
         CPDFAnnotation *annotation = self.annotManage.pdfListView.activeAnnotations.firstObject;
-        if([annotation isKindOfClass:[CPDFStampAnnotation class]] || [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||  [annotation isKindOfClass:[CPDFSoundAnnotation class]] || (CPDFViewAnnotationModeSound == self.selectedIndex)) {
+        if([annotation isKindOfClass:[CPDFStampAnnotation class]] || [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||  [annotation isKindOfClass:[CPDFSoundAnnotation class]] || (CPDFViewAnnotationModeSound == self.selectedIndex) || [annotation isKindOfClass:[CPDFLinkAnnotation class]] || (CPDFViewAnnotationModeLink == self.selectedIndex)) {
             self.propertiesBtn.enabled = NO;
         } else {
             self.propertiesBtn.enabled = YES;
@@ -335,6 +335,8 @@
         self.propertiesBtn.enabled = NO;
         if(CPDFViewAnnotationModeSound == self.selectedIndex) {
             [self.pdfListView stopRecord];
+        } else if (CPDFViewAnnotationModeFreeText == self.selectedIndex) {
+            [self.pdfListView commitEditAnnotationFreeText];
         }
         self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
         self.selectedIndex = 0;
@@ -477,6 +479,7 @@
             linkVC.pageCount = self.annotManage.pdfListView.document.pageCount;
             linkVC.delegate = self;
             presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:linkVC presentingViewController:self.parentVC];
+            presentationController.tapDelegate = self;
             linkVC.transitioningDelegate = presentationController;
             [self.parentVC presentViewController:linkVC animated:YES completion:nil];
         }
@@ -530,6 +533,7 @@
         AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
         CPDFStampViewController *stampVC = [[CPDFStampViewController alloc] init];
         presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:stampVC presentingViewController:self.parentVC];
+        presentationController.tapDelegate = self;
         stampVC.delegate = self;
         stampVC.transitioningDelegate = presentationController;
         [self.parentVC presentViewController:stampVC animated:YES completion:nil];
@@ -605,7 +609,13 @@
 #pragma mark - AAPLCustomPresentationControllerDelegate
 
 - (void)AAPLCustomPresentationControllerTap:(AAPLCustomPresentationController *)AAPLCustomPresentationController {
-    self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
+    CPDFAnnotation *annotation = self.annotManage.pdfListView.activeAnnotations.firstObject;
+    if([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
+        
+    } else if (CPDFViewAnnotationModeSignature == self.selectedIndex || CPDFViewAnnotationModeStamp == self.selectedIndex) {
+        self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
+    }
+   
 }
 
 #pragma mark - UIImagePickerControllerDelegate