|
@@ -18,7 +18,7 @@
|
|
|
|
|
|
#import <compdfkit_tools/CPDFColorUtils.h>
|
|
|
|
|
|
-@interface CPDFSignatureEditViewController () <UIPopoverPresentationControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate>
|
|
|
+@interface CPDFSignatureEditViewController () <UIPopoverPresentationControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIColorPickerViewControllerDelegate, UITextFieldDelegate, CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate>
|
|
|
|
|
|
@property (nonatomic, strong) CPDFColorSelectView *colorSelectView;
|
|
|
|
|
@@ -42,6 +42,14 @@
|
|
|
|
|
|
@property (nonatomic, assign) CSignatureTopBarSelectedIndex selecIndex;
|
|
|
|
|
|
+@property (nonatomic, strong) UIView *thicknessView;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UILabel *thicknessLabel;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UISlider *thicknessSlider;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIButton *clearButton;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation CPDFSignatureEditViewController
|
|
@@ -71,12 +79,30 @@
|
|
|
self.signatureDrawImageView.lineWidth = 4;
|
|
|
[self.view addSubview:self.signatureDrawImageView];
|
|
|
self.signatureDrawImageView.hidden = YES;
|
|
|
-
|
|
|
- self.colorSelectView = [[CPDFColorSelectView alloc] initWithFrame:CGRectMake(0, 550, self.view.frame.size.width, 90)];
|
|
|
+
|
|
|
+ self.colorSelectView = [[CPDFColorSelectView alloc] init];
|
|
|
+ [self.colorSelectView.colorLabel removeFromSuperview];
|
|
|
self.colorSelectView.delegate = self;
|
|
|
- self.colorSelectView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
|
|
[self.view addSubview:self.colorSelectView];
|
|
|
|
|
|
+ self.thicknessView = [[UIView alloc] init];
|
|
|
+ self.thicknessView.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
|
|
|
+ [self.view addSubview:self.thicknessView];
|
|
|
+
|
|
|
+ self.thicknessLabel = [[UILabel alloc] init];
|
|
|
+ self.thicknessLabel.text = NSLocalizedString(@"Thicness", nil);
|
|
|
+ self.thicknessLabel.textColor = [UIColor grayColor];
|
|
|
+ self.thicknessLabel.font = [UIFont systemFontOfSize:12.0];
|
|
|
+ [self.thicknessView addSubview:self.thicknessLabel];
|
|
|
+
|
|
|
+ self.thicknessSlider = [[UISlider alloc] init];
|
|
|
+ self.thicknessSlider.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
|
|
+ self.thicknessSlider.value = 5;
|
|
|
+ self.thicknessSlider.maximumValue = 20;
|
|
|
+ self.thicknessSlider.minimumValue = 1;
|
|
|
+ [self.thicknessSlider addTarget:self action:@selector(buttonItemClicked_changes:) forControlEvents:UIControlEventValueChanged];
|
|
|
+ [self.thicknessView addSubview:self.thicknessSlider];
|
|
|
+
|
|
|
self.cacelButon = [[UIButton alloc] init];
|
|
|
[self.cacelButon setTitle:NSLocalizedString(@"Cancel", nil) forState:UIControlStateNormal];
|
|
|
[self.cacelButon setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
|
|
@@ -94,6 +120,8 @@
|
|
|
self.bottomBorder = [CALayer layer];
|
|
|
self.bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
|
|
|
self.textField = [[UITextField alloc] init];
|
|
|
+ self.textField.delegate = self;
|
|
|
+ self.textField.placeholder = NSLocalizedString(@"Signature Here", nil);
|
|
|
self.textField.textAlignment = NSTextAlignmentCenter;
|
|
|
self.textField.font = [UIFont systemFontOfSize:30];
|
|
|
[self.view addSubview:self.textField];
|
|
@@ -109,6 +137,17 @@
|
|
|
[self.view addSubview:self.createButton];
|
|
|
self.createButton.hidden = YES;
|
|
|
|
|
|
+ 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.borderWidth = 1.0;
|
|
|
+ self.clearButton.layer.cornerRadius = 25.0;
|
|
|
+ self.clearButton.layer.masksToBounds = YES;
|
|
|
+ [self.clearButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
|
|
+ [self.clearButton addTarget:self action:@selector(buttonItemClicked_clear:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [self.view addSubview:self.clearButton];
|
|
|
+
|
|
|
self.selecIndex = CSignatureTopBarDefault;
|
|
|
self.view.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
|
|
|
[self createGestureRecognizer];
|
|
@@ -117,20 +156,36 @@
|
|
|
- (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);
|
|
|
+
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
- self.colorSelectView.frame = CGRectMake(0, self.view.safeAreaInsets.top, self.view.frame.size.width, 90);
|
|
|
- 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/2);
|
|
|
+ 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.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);
|
|
|
+
|
|
|
+ } 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.signatureDrawImageView.frame = self.signatureDrawTextView.frame;
|
|
|
self.createButton.frame = CGRectMake(self.view.frame.size.width - 70 - self.view.safeAreaInsets.right, self.view.frame.size.height - 100 - self.view.safeAreaInsets.bottom, 50, 50);
|
|
|
+ self.clearButton.frame = CGRectMake(self.view.frame.size.width - 70 - self.view.safeAreaInsets.right, self.view.frame.size.height - 100 - self.view.safeAreaInsets.bottom, 50, 50);
|
|
|
} else {
|
|
|
self.colorSelectView.frame = CGRectMake(0, 64, self.view.frame.size.width, 90);
|
|
|
+ self.thicknessView.frame = CGRectMake(20, self.view.safeAreaInsets.top, self.view.frame.size.width-40, 90);
|
|
|
self.signatureDrawTextView.frame = CGRectMake(0, 190, self.view.frame.size.width, self.view.frame.size.height/2);
|
|
|
self.signatureDrawImageView.frame = self.signatureDrawTextView.frame;
|
|
|
self.createButton.frame = CGRectMake(self.view.frame.size.width - 70, self.view.frame.size.height - 100, 50, 50);
|
|
|
+ self.clearButton.frame = CGRectMake(self.view.frame.size.width - 70, self.view.frame.size.height - 100, 50, 50);
|
|
|
}
|
|
|
|
|
|
self.textField.frame = CGRectMake((self.view.frame.size.width - 300)/2, 200, 300, 100);
|
|
|
- self.bottomBorder.frame = CGRectMake(0, self.textField.frame.size.height - 1, self.textField.frame.size.width, 1.0);
|
|
|
}
|
|
|
|
|
|
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
|
@@ -216,6 +271,7 @@
|
|
|
self.selecIndex = CSignatureTopBarText;
|
|
|
self.colorSelectView.hidden = NO;
|
|
|
self.createButton.hidden = YES;
|
|
|
+ self.thicknessView.hidden = YES;
|
|
|
} else if (self.segmentedControl.selectedSegmentIndex == 2) {
|
|
|
self.colorSelectView.hidden = YES;
|
|
|
self.signatureDrawTextView.hidden = YES;
|
|
@@ -225,10 +281,55 @@
|
|
|
self.createButton.hidden = NO;
|
|
|
self.colorSelectView.hidden = YES;
|
|
|
self.signatureDrawImageView.selectIndex = CSignatureDrawImage;
|
|
|
+ self.thicknessView.hidden = YES;
|
|
|
[self.signatureDrawImageView setNeedsDisplay];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)buttonItemClicked_changes:(UISlider *)sender {
|
|
|
+ self.signatureDrawTextView.lineWidth = sender.value;
|
|
|
+ [self.signatureDrawTextView setNeedsDisplay];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)buttonItemClicked_clear:(UIButton *)button {
|
|
|
+ if (self.segmentedControl.selectedSegmentIndex == 0) {
|
|
|
+ [self.signatureDrawTextView signatureClear];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - UITextFieldDelegate
|
|
|
+
|
|
|
+- (void)textFieldDidBeginEditing:(UITextField *)textField {
|
|
|
+ if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
|
|
|
+ [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
|
|
|
+ self.clearButton.center = CGPointMake(self.clearButton.center.x, self.clearButton.center.y-300);
|
|
|
+ } completion:nil];
|
|
|
+ } else {
|
|
|
+ [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
|
|
|
+ self.clearButton.center = CGPointMake(self.clearButton.center.x, self.clearButton.center.y-200);
|
|
|
+ self.textField.center = CGPointMake(self.textField.center.x, self.textField.center.y-100);
|
|
|
+ } completion:nil];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)textFieldDidEndEditing:(UITextField *)textField {
|
|
|
+ if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
|
|
|
+ [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
|
|
|
+ self.clearButton.center = CGPointMake(self.clearButton.center.x, self.clearButton.center.y+300);
|
|
|
+ } completion:nil];
|
|
|
+ } else {
|
|
|
+ [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
|
|
|
+ self.clearButton.center = CGPointMake(self.clearButton.center.x, self.clearButton.center.y+200);
|
|
|
+ self.textField.center = CGPointMake(self.textField.center.x, self.textField.center.y+100);
|
|
|
+ } completion:nil];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)textFieldShouldReturn:(UITextField *)textField {
|
|
|
+ [textField resignFirstResponder];
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Private Methods
|
|
|
|
|
|
- (void)createImageSignature {
|
|
@@ -303,14 +404,21 @@
|
|
|
- (void)selectColorView:(CPDFColorSelectView *)select color:(UIColor *)color {
|
|
|
self.textField.textColor = color;
|
|
|
self.signatureDrawTextView.color = color;
|
|
|
+ [self.signatureDrawTextView setNeedsDisplay];
|
|
|
}
|
|
|
|
|
|
- (void)selectColorView:(CPDFColorSelectView *)select {
|
|
|
- _colorPicker = [[CPDFColorPickerView alloc] initWithFrame:self.view.frame];
|
|
|
- _colorPicker.delegate = self;
|
|
|
- _colorPicker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
- _colorPicker.backgroundColor = [UIColor whiteColor];
|
|
|
- [self.view addSubview:self.colorPicker];
|
|
|
+ if (@available(iOS 14.0, *)) {
|
|
|
+ UIColorPickerViewController *picker = [[UIColorPickerViewController alloc] init];
|
|
|
+ picker.delegate = self;
|
|
|
+ [self presentViewController:picker animated:YES completion:nil];
|
|
|
+ } else {
|
|
|
+ self.colorPicker = [[CPDFColorPickerView alloc] initWithFrame:self.view.frame];
|
|
|
+ self.colorPicker.delegate = self;
|
|
|
+ self.colorPicker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
+ self.colorPicker.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
|
|
|
+ [self.view addSubview:self.colorPicker];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#pragma mark - CPDFColorPickerViewDelegate
|
|
@@ -318,6 +426,16 @@
|
|
|
- (void)pickerView:(CPDFColorPickerView *)colorPickerView color:(UIColor *)color {
|
|
|
self.signatureDrawTextView.color = color;
|
|
|
self.textField.textColor = color;
|
|
|
+ [self.signatureDrawImageView setNeedsDisplay];
|
|
|
}
|
|
|
|
|
|
+#pragma mark - UIColorPickerViewControllerDelegate
|
|
|
+
|
|
|
+- (void)colorPickerViewControllerDidFinish:(UIColorPickerViewController *)viewController API_AVAILABLE(ios(14.0)) {
|
|
|
+ self.signatureDrawTextView.color = viewController.selectedColor;
|
|
|
+ self.textField.textColor = self.signatureDrawTextView.color;
|
|
|
+ [self.signatureDrawTextView setNeedsDisplay];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
@end
|