|
@@ -8,11 +8,14 @@
|
|
|
#import "CPDFTextViewController.h"
|
|
|
#import "CPDFTextView.h"
|
|
|
#import "CPDFDataModel.h"
|
|
|
+#import "CPDFDrawView.h"
|
|
|
+#import "CPDFClipView.h"
|
|
|
#import "Masonry.h"
|
|
|
|
|
|
-@interface CPDFTextViewController ()
|
|
|
+@interface CPDFTextViewController () <CPDFTextPreviewDelegate,CPDFClipTextPreviewDelegate,UITextFieldDelegate>
|
|
|
|
|
|
@property (nonatomic,strong) CPDFDrawView *drawView;
|
|
|
+@property (nonatomic,strong) CPDFClipView *cliView;
|
|
|
|
|
|
@end
|
|
|
|
|
@@ -24,6 +27,10 @@
|
|
|
|
|
|
_textPreview = [[CPDFTextPreview alloc] init];
|
|
|
_textView = [[CPDFTextView alloc] init];
|
|
|
+
|
|
|
+ _textView.verticalField.delegate = self;
|
|
|
+ _textView.horizontalField.delegate = self;
|
|
|
+
|
|
|
_dataModel = [[CPDFDataModel alloc] init];
|
|
|
_alertController = [UIAlertController alertControllerWithTitle:@"Watermark Content" message:nil preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
@@ -126,12 +133,18 @@
|
|
|
[self.view addSubview:_drawView];
|
|
|
[self.textPreview bringSubviewToFront:_drawView];
|
|
|
|
|
|
+ _cliView = [[CPDFClipView alloc] initWithFrame:self.textPreview.bounds];
|
|
|
+ _cliView.delegate = self;
|
|
|
+ [self.view addSubview:_cliView];
|
|
|
+ [self.drawView bringSubviewToFront:_cliView];
|
|
|
+
|
|
|
} else {
|
|
|
_dataModel.isTile = NO;
|
|
|
_textView.horizontalField.enabled = NO;
|
|
|
_textView.verticalField.enabled = NO;
|
|
|
_textView.textScaleSlider.enabled = YES;
|
|
|
[_drawView removeFromSuperview];
|
|
|
+ [_cliView removeFromSuperview];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -260,8 +273,6 @@
|
|
|
CGContextSetFillColorWithColor(context, self.textPreview.watermarkLabel.textColor.CGColor);
|
|
|
CGContextSaveGState(context);
|
|
|
|
|
|
- CGContextClipToRect(context, self.textPreview.documentView.frame);
|
|
|
-
|
|
|
UIFont *font = [UIFont systemFontOfSize:self.textView.textScaleSlider.value];
|
|
|
NSDictionary *dic = @{NSFontAttributeName:font,NSForegroundColorAttributeName:self.textPreview.watermarkLabel.textColor};
|
|
|
|
|
@@ -285,11 +296,59 @@
|
|
|
[@"watermark" drawInRect:CGRectMake(a + i * width, b + j * height, width - 10, height - 10) withAttributes:dic];
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - CPDFClipTextPreviewDelegate
|
|
|
+
|
|
|
+- (void)clipText:(CGContextRef)context {
|
|
|
+ CGContextSetFillColorWithColor(context, [UIColor systemGray5Color].CGColor);
|
|
|
+ CGContextFillRect(context, self.textPreview.bounds);
|
|
|
+ CGContextClearRect(context, self.textPreview.documentView.frame);
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - UITextFieldDelegate
|
|
|
+
|
|
|
+- (void)textFieldDidBeginEditing:(UITextField *)textField {
|
|
|
+
|
|
|
+ self.cliView.hidden = YES;
|
|
|
+ self.drawView.hidden = YES;
|
|
|
+
|
|
|
+ if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.height.mas_equalTo(205);
|
|
|
+ make.width.equalTo(_textPreview.mas_width);
|
|
|
+ make.bottom.equalTo(self.view.mas_bottom).offset(-500);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
|
|
|
+ self.textView.center = CGPointMake(self.textView.center.x, self.textView.center.y - 500);
|
|
|
+ } completion:nil];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)textFieldShouldReturn:(UITextField *)textField {
|
|
|
+ [textField resignFirstResponder];
|
|
|
|
|
|
- CGContextRestoreGState(context);
|
|
|
+ self.cliView.hidden = NO;
|
|
|
+ self.drawView.hidden = NO;
|
|
|
|
|
|
- //self.drawView.transform = CGAffineTransformMakeRotation((self.dataModel.watermarkRotation * M_PI) / 180);
|
|
|
+ if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.equalTo(_textPreview.mas_bottom).offset(0);
|
|
|
+ make.width.equalTo(_textPreview.mas_width);
|
|
|
+ make.bottom.equalTo(self.view.mas_bottom).offset(0);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
|
|
|
+ self.textView.center = CGPointMake(self.textView.center.x, self.textView.center.y + 300);
|
|
|
+ } completion:nil];
|
|
|
+ }
|
|
|
|
|
|
+ return YES;
|
|
|
}
|
|
|
|
|
|
@end
|