Browse Source

PDFTool(iOS)-自测修改

yangliuhua 1 year ago
parent
commit
4d7daae52c

+ 20 - 7
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFSignature/CPDFSignatureEditViewController.m

@@ -18,7 +18,7 @@
 
 #import <compdfkit_tools/CPDFColorUtils.h>
 
-@interface CPDFSignatureEditViewController () <UIPopoverPresentationControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIColorPickerViewControllerDelegate, UITextFieldDelegate, CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate>
+@interface CPDFSignatureEditViewController () <UIPopoverPresentationControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIColorPickerViewControllerDelegate, UITextFieldDelegate, CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate, CSignatureDrawViewDelegate>
 
 @property (nonatomic, strong) CPDFColorSelectView *colorSelectView;
 
@@ -69,12 +69,14 @@
     self.navigationItem.titleView = self.segmentedControl;
     
     self.signatureDrawTextView = [[CSignatureDrawView alloc] init];
+    self.signatureDrawTextView.delegate = self;
     self.signatureDrawTextView.color = [UIColor blackColor];
     self.signatureDrawTextView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
     self.signatureDrawTextView.lineWidth = 4;
     [self.view addSubview:self.signatureDrawTextView];
     
     self.signatureDrawImageView = [[CSignatureDrawView alloc] init];
+    self.signatureDrawImageView.delegate = self;
     self.signatureDrawImageView.color = [UIColor blackColor];
     self.signatureDrawImageView.lineWidth = 4;
     [self.view addSubview:self.signatureDrawImageView];
@@ -105,14 +107,14 @@
     
     self.cacelButon = [[UIButton alloc] init];
     [self.cacelButon setTitle:NSLocalizedString(@"Cancel", nil) forState:UIControlStateNormal];
-    [self.cacelButon setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
+    [self.cacelButon setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
     [self.cacelButon addTarget:self action:@selector(buttonItemClicked_Cancel:) forControlEvents:UIControlEventTouchUpInside];
     UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithCustomView:self.cacelButon];
     self.navigationItem.leftBarButtonItem = cancelItem;
     
     self.saveButton = [[UIButton alloc] init];
     [self.saveButton setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
-    [self.saveButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
+    [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
     [self.saveButton addTarget:self action:@selector(buttonItemClicked_Save:) forControlEvents:UIControlEventTouchUpInside];
     UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithCustomView:self.saveButton];
     self.navigationItem.rightBarButtonItem = doneItem;
@@ -140,7 +142,7 @@
     self.clearButton = [[UIButton alloc] init];
     [self.clearButton setImage:[UIImage imageNamed:@"CPDFSignatureImageClean" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
     self.clearButton.titleLabel.adjustsFontSizeToFitWidth = YES;
-    self.clearButton.layer.borderColor = [UIColor purpleColor].CGColor;
+    self.clearButton.layer.borderColor = [UIColor grayColor].CGColor;
     self.clearButton.layer.borderWidth = 1.0;
     self.clearButton.layer.cornerRadius = 25.0;
     self.clearButton.layer.masksToBounds = YES;
@@ -156,21 +158,22 @@
 - (void)viewWillLayoutSubviews {
     [super viewWillLayoutSubviews];
     self.colorPicker.frame = CGRectMake(0, self.view.frame.size.height/2, self.view.frame.size.width, self.view.frame.size.height/2);
+    self.segmentedControl.frame = CGRectMake(0, 40, 280, 30);
    
     if (@available(iOS 11.0, *)) {
         if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
             self.colorSelectView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
-            self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top+60, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
+            self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top+90, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
             self.thicknessLabel.frame = CGRectMake(20, 15, 60, 30);
             self.thicknessSlider.frame = CGRectMake(90, 0, self.thicknessView.bounds.size.width-110, 60);
-            self.signatureDrawTextView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 120, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height/2);
+            self.signatureDrawTextView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 150, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom-150);
             
         } else {
             self.colorSelectView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top-15, 380, 60);
             self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left+380, self.view.safeAreaInsets.top, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right-380, 60);
             self.thicknessLabel.frame = CGRectMake(20, 15, 60, 30);
             self.thicknessSlider.frame = CGRectMake(90, 0, self.thicknessView.bounds.size.width-110, 60);
-            self.signatureDrawTextView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 60, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height/2);
+            self.signatureDrawTextView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 90, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom-90);
         }
         
         self.signatureDrawImageView.frame = self.signatureDrawTextView.frame;
@@ -262,6 +265,7 @@
         self.selecIndex = CSignatureTopBarDefault;
         self.colorSelectView.hidden = NO;
         self.createButton.hidden = YES;
+        self.clearButton.hidden = NO;
         self.signatureDrawTextView.selectIndex = CSignatureDrawText;
     } else if (self.segmentedControl.selectedSegmentIndex == 1) {
         self.colorSelectView.hidden = NO;
@@ -272,6 +276,8 @@
         self.colorSelectView.hidden = NO;
         self.createButton.hidden = YES;
         self.thicknessView.hidden = YES;
+        self.clearButton.hidden = NO;
+        [self.textField resignFirstResponder];
     } else if (self.segmentedControl.selectedSegmentIndex == 2) {
         self.colorSelectView.hidden = YES;
         self.signatureDrawTextView.hidden = YES;
@@ -282,6 +288,7 @@
         self.colorSelectView.hidden = YES;
         self.signatureDrawImageView.selectIndex = CSignatureDrawImage;
         self.thicknessView.hidden = YES;
+        self.clearButton.hidden = YES;
         [self.signatureDrawImageView setNeedsDisplay];
     }
 }
@@ -323,6 +330,7 @@
             self.textField.center = CGPointMake(self.textField.center.x, self.textField.center.y+100);
         } completion:nil];
     }
+    [self.saveButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
 }
 
 - (BOOL)textFieldShouldReturn:(UITextField *)textField {
@@ -437,5 +445,10 @@
     [self.signatureDrawTextView setNeedsDisplay];
 }
 
+#pragma mark - CSignatureDrawViewDelegate
+
+- (void)signatureDrawViewStart:(CSignatureDrawView *)signatureDrawView {
+    [self.saveButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
+}
 
 @end

+ 12 - 0
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFSignature/CSignatureDrawView.h

@@ -14,6 +14,16 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+@class CSignatureDrawView;
+
+@protocol CSignatureDrawViewDelegate <NSObject>
+
+@optional
+
+- (void)signatureDrawViewStart:(CSignatureDrawView *)signatureDrawView;
+
+@end
+
 typedef NS_ENUM(NSInteger, CSignatureDrawSelectedIndex) {
     CSignatureDrawText = 0,
     CSignatureDrawImage
@@ -27,6 +37,8 @@ typedef NS_ENUM(NSInteger, CSignatureDrawSelectedIndex) {
 
 @property (nullable, nonatomic, strong) UIImage *image;
 
+@property (nonatomic, weak) id<CSignatureDrawViewDelegate> delegate;
+
 @property (nonatomic, assign) CSignatureDrawSelectedIndex selectIndex;
 
 - (UIImage *)signatureImage;

+ 25 - 1
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFSignature/CSignatureDrawView.m

@@ -19,6 +19,10 @@ static NSInteger _index;
 
 @property (nonatomic, strong) UIBezierPath *bezierPath;
 
+@property (nonatomic, assign) CGRect textRect;
+
+@property (nonatomic, assign) CGContextRef context;
+
 @end
 
 @implementation CSignatureDrawView
@@ -43,6 +47,8 @@ static NSInteger _index;
 - (void)drawRect:(CGRect)rect {
     [super drawRect:rect];
     
+    self.context = UIGraphicsGetCurrentContext();
+    
     if (CSignatureDrawText == self.selectIndex) {
         [self.color set];
         [self.bezierPath setLineWidth:self.lineWidth];
@@ -53,9 +59,23 @@ static NSInteger _index;
         if (self.image) {
             CGRect imageFrame = [self imageFrameInRect:rect];
             [self.image drawInRect:imageFrame];
+            if (self.delegate && [self.delegate respondsToSelector:@selector(signatureDrawViewStart:)]) {
+                [self.delegate signatureDrawViewStart:self];
+            }
         }
     }
-        
+    
+    NSString *string = @"Sign here";
+    self.textRect = CGRectInset(rect, (rect.size.width/7)*2, (rect.size.height/7)*3);
+    UIFont *font = [UIFont systemFontOfSize:30];
+    NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:font, NSForegroundColorAttributeName:[UIColor grayColor]}];
+    CGSize textSize = [attributedText boundingRectWithSize:rect.size options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) context:nil].size;
+
+    CGFloat x = self.textRect.origin.x + (self.textRect.size.width - textSize.width) / 2.0;
+    CGFloat y = self.textRect.origin.y + (self.textRect.size.height - textSize.height) / 2.0;
+    CGPoint center = CGPointMake(x, y);
+
+    [attributedText drawAtPoint:center];
 }
 
 #pragma mark - Draw Methods
@@ -150,6 +170,10 @@ static NSInteger _index;
     CGPoint point = [[touches anyObject] locationInView:self];
     _index = 0;
     _points[0] = point;
+    
+    if (self.delegate && [self.delegate respondsToSelector:@selector(signatureDrawViewStart:)]) {
+        [self.delegate signatureDrawViewStart:self];
+    }
 }
 
 - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

+ 2 - 5
compdfkit-tools/compdfkit-tools/Common/Utils/CPDFColorUtils.m

@@ -42,7 +42,7 @@
     if (@available(iOS 13.0, *)) {
         return [UIColor colorNamed:@"CAnnotationSampleDrawBackgoundColor" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
     } else {
-        return [UIColor colorWithRed:250.0/255.0 green:252.0/255.0  blue:1.0 alpha:1.0];
+        return [UIColor colorWithRed:255.0/255.0 green:255.0/255.0  blue:1.0 alpha:1.0];
     }
 }
 
@@ -50,7 +50,7 @@
     if (@available(iOS 13.0, *)) {
         return [UIColor colorNamed:@"CAnnotationPropertyViewControllerBackgoundColor" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
     } else {
-        return [UIColor colorWithRed:250.0/255.0 green:252.0/255.0  blue:1.0 alpha:1.0];
+        return [UIColor colorWithRed:255.0/255.0 green:255.0/255.0  blue:1.0 alpha:1.0];
     }
 }
 
@@ -78,9 +78,6 @@
     }
 }
 
-
-
-
 + (UIColor *)CViewBackgroundColor {
     if (@available(iOS 13.0, *)) {
         return [UIColor colorNamed:@"CViewBackgroundColor" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];

+ 1 - 1
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFAnnotationSampleView.m

@@ -46,7 +46,7 @@
 - (void)drawRect:(CGRect)rect {
     [super drawRect:rect];
     CGContextRef context = UIGraphicsGetCurrentContext();
-    self.centerRect = CGRectInset(rect, 130, (self.bounds.size.height/8)*3);
+    self.centerRect = CGRectInset(rect, (self.bounds.size.width/20)*9, (self.bounds.size.height/8)*3);
     self.arrowRect = CGRectInset(rect, 100, 20);
     
     self.textRect = CGRectInset(rect, self.bounds.size.width/3+3, self.bounds.size.height/3);

+ 49 - 14
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFColorSelectView.m

@@ -16,7 +16,7 @@
 
 @interface  CPDFColorSelectView ()
 
-@property (nonatomic, strong) UIView *colorPickerView;
+@property (nonatomic, strong) UIScrollView *colorPickerView;
 
 @property (nonatomic, strong) NSMutableArray *colorArray;
 
@@ -51,29 +51,61 @@
         [self addSubview:self.colorLabel];
         
         self.colorArray = [NSMutableArray array];
-        
-        self.colorPickerView = [[UIView alloc] initWithFrame:CGRectMake(0, 30, self.bounds.size.width, 60)];
+        self.colorPickerView = [[UIScrollView alloc] init];
         self.colorPickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+        
+//        self.view1 = [[UIView alloc] init];
+//        [self addSubview:self.view1];
+//        [self.colorArray addObject:self.view1];
+//
+//        self.view2 = [[UIView alloc] init];
+//        [self addSubview:self.view1];
+//        [self.colorArray addObject:self.view2];
+//
+//        self.view3 = [[UIView alloc] init];
+//        [self addSubview:self.view3];
+//        [self.colorArray addObject:self.view3];
+//
+//        self.view4 = [[UIView alloc] init];
+//        [self addSubview:self.view4];
+//        [self.colorArray addObject:self.view4];
+//
+//        self.view5 = [[UIView alloc] init];
+//        [self addSubview:self.view5];
+//        [self.colorArray addObject:self.view5];
+//
+//        self.view6 = [[UIView alloc] init];
+//        [self addSubview:self.view6];
+//        [self.colorArray addObject:self.view6];
+//
+//        self.view7 = [[UIView alloc] init];
+//        [self addSubview:self.view7];
+//        [self.colorArray addObject:self.view7];
+//
+//        self.view8 = [[UIView alloc] init];
+//        [self addSubview:self.view8];
+//        [self.colorArray addObject:self.view8];
+        
         [self addSubview:self.colorPickerView];
     }
     return self;
 }
 
 - (void)pickerBarInit {
-    NSArray *colors = @[[UIColor redColor],
-                        [UIColor yellowColor],
-                        [UIColor blueColor],
-                        [UIColor colorWithRed:100.0/255.0 green:188.0/255.0 blue:56.0/255.0 alpha:1.0],
-                        [UIColor colorWithRed:79.0/255.0 green:205.0/255.0 blue:160.0/255.0 alpha:1.0],
-                        [UIColor colorWithRed:255.0/255.0 green:140.0/255.0 blue:103.0/255.0 alpha:1.0],
-                        [UIColor colorWithRed:223.0/255.0 green:190.0/255.0 blue:94.0/255.0 alpha:1.0],
+    NSArray *colors = @[[UIColor colorWithRed:233.0/255.0 green:27.0/255.0 blue:0.0 alpha:1.0],
+                        [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],
+                        [UIColor colorWithRed:0.0/255.0 green:188.0/255.0 blue:162.0/255.0 alpha:1.0],
+                        [UIColor colorWithRed:61.0/255.0 green:136.0/255.0 blue:71.0/255.0 alpha:1.0],
+                        [UIColor colorWithRed:91.0/255.0 green:122.0/255.0 blue:162.0/255.0 alpha:1.0],
+                        [UIColor colorWithRed:92.0/255.0 green:187.0/255.0 blue:247.0/255.0 alpha:1.0],
+                        [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
                         [UIColor clearColor]];
     NSMutableArray *array = [NSMutableArray array];
     for (int i = 0; i < colors.count; i++) {
-        UIView *view = [[UIButton alloc] init];
+        UIView *view = [[UIView alloc] init];
         view.tag = i;
-        view.frame = CGRectMake((self.bounds.size.width - 16 - ((self.colorPickerView.bounds.size.height - 26)*8))/9 * (i+1) + (self.colorPickerView.bounds.size.height - 26) * i, 5, self.colorPickerView.bounds.size.height - 26, self.colorPickerView.bounds.size.height - 26);
-        [[view layer] setCornerRadius:(self.colorPickerView.bounds.size.height - 26)/2];
+        view.frame = CGRectMake((self.bounds.size.width + 100 - 16 - ((self.colorPickerView.bounds.size.height - 16)*8))/9 * (i+1) + (self.colorPickerView.bounds.size.height - 16) * i, 5, self.colorPickerView.bounds.size.height - 16, self.colorPickerView.bounds.size.height - 16);
+        [[view layer] setCornerRadius:(self.colorPickerView.bounds.size.height - 16)/2];
         view.layer.borderColor = [UIColor whiteColor].CGColor;
         view.layer.borderWidth = 1.0;
         view.backgroundColor = [CPDFColorUtils CPDFViewControllerBackgroundColor];
@@ -83,8 +115,10 @@
         UIButton *button = [[UIButton alloc] init];
         [self.colorPickerView addSubview:button];
         button.frame = CGRectInset(view.frame, 3, 3);
-        [[button layer] setCornerRadius:(self.colorPickerView.bounds.size.height - 32)/2];
+        [[button layer] setCornerRadius:(self.colorPickerView.bounds.size.height - 22)/2];
         button.layer.masksToBounds = YES;
+        button.layer.borderWidth = 0.5;
+        button.layer.borderColor = [UIColor grayColor].CGColor;
         button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
         button.backgroundColor = colors[i];
         button.tag = i;
@@ -100,6 +134,7 @@
     [super layoutSubviews];
     self.colorLabel.frame = CGRectMake(20, 0, 50, self.bounds.size.height/3);
     self.colorPickerView.frame = CGRectMake(8, self.bounds.size.height/3, self.bounds.size.width-16, 60);
+    self.colorPickerView.contentSize = CGSizeMake(self.bounds.size.width+100, 60);
     [self pickerBarInit];
 }
 

+ 1 - 1
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFOpacitySliderView.m

@@ -70,7 +70,7 @@
 
 - (void)layoutSubviews {
     [super layoutSubviews];
-    self.titleLabel.frame = CGRectMake(10, 0, self.frame.size.width, self.frame.size.height/2);
+    self.titleLabel.frame = CGRectMake(20, 0, self.frame.size.width, self.frame.size.height/2);
     self.opacitySlider.frame = CGRectMake(20 - self.leftMargin, self.frame.size.height/2, self.frame.size.width - 130 + self.leftMargin + self.rightMargin, self.frame.size.height/2);
 
     self.startLabel.frame = CGRectMake(self.frame.size.width - 100 + self.rightMargin, self.frame.size.height/2 + 7.5, 80, self.frame.size.height/2 - 15);

+ 0 - 3
viewer-ctrl-demo/viewer-ctrl-demo/CPDFViewController.m

@@ -423,13 +423,10 @@
 - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
     
     __weak typeof(self) weakSelf = self;
-    //获取授权
     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];