|
@@ -7,44 +7,55 @@
|
|
|
|
|
|
#import "CPDFAddViewController.h"
|
|
|
#import <ComPDFKit/ComPDFKit.h>
|
|
|
+#import <ComPDFKit/CPDFWatermark.h>
|
|
|
#import "CPDFViewController.h"
|
|
|
#import "CPDFTextView.h"
|
|
|
#import "CPDFTextPreview.h"
|
|
|
#import "CPDFImageView.h"
|
|
|
#import "CPDFImagePreview.h"
|
|
|
#import "CPDFDataModel.h"
|
|
|
+#import "CPDFEditView.h"
|
|
|
#import "Masonry.h"
|
|
|
|
|
|
-@interface CPDFAddViewController ()
|
|
|
+@interface CPDFAddViewController () <UITableViewDelegate,UITableViewDataSource>
|
|
|
|
|
|
@property (nonatomic,assign) CGSize imageSize;
|
|
|
-@property (nonatomic,strong) CPDFView *pdfView;
|
|
|
@property (nonatomic,strong) UIImage *image;
|
|
|
@property (nonatomic,strong) CPDFDataModel *dataModel;
|
|
|
+@property (nonatomic,strong) CPDFEditView *editView;
|
|
|
+@property (nonatomic,strong) NSMutableArray *dataArray;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation CPDFAddViewController
|
|
|
|
|
|
-- (instancetype)initWithImage:(UIImage *)image {
|
|
|
- self = [super init];
|
|
|
- if (self) {
|
|
|
- _image = image;
|
|
|
- _imageSize = image.size;
|
|
|
- }
|
|
|
- return self;
|
|
|
-}
|
|
|
-
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
// Do any additional setup after loading the view.
|
|
|
+
|
|
|
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(onClickedDoneBtn)];
|
|
|
- self.navigationItem.rightBarButtonItem = doneBtn;
|
|
|
+
|
|
|
+ UIBarButtonItem *editBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editClick)];
|
|
|
+ UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelClick)];
|
|
|
+
|
|
|
+ self.navigationItem.rightBarButtonItems = @[doneBtn,editBtn,cancelBtn];
|
|
|
|
|
|
[self createView];
|
|
|
[self addConstraint];
|
|
|
}
|
|
|
|
|
|
+#pragma mark - Initializers
|
|
|
+
|
|
|
+- (instancetype)initWithImage:(UIImage *)image withDocument:(CPDFDocument *)document{
|
|
|
+ self = [super init];
|
|
|
+ if (self) {
|
|
|
+ _image = image;
|
|
|
+ _imageSize = image.size;
|
|
|
+ _document = document;
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
- (void)createView {
|
|
|
NSArray *segmentArray = @[@"Text",@"Image"];
|
|
|
_segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentArray];
|
|
@@ -65,6 +76,12 @@
|
|
|
[self.view addSubview:_textViewController.view];
|
|
|
[self.view addSubview:_imageViewController.view];
|
|
|
|
|
|
+ _editView = [[CPDFEditView alloc] init];
|
|
|
+ _editView.editTableView.dataSource = self;
|
|
|
+ _editView.editTableView.delegate = self;
|
|
|
+
|
|
|
+ [self.view addSubview:_editView];
|
|
|
+
|
|
|
_textViewController.textPreview.documentView.image = self.image;
|
|
|
_imageViewController.imagePreview.documentView.image = self.image;
|
|
|
_imageViewController.view.hidden = YES;
|
|
@@ -161,6 +178,51 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#pragma mark - Accessors
|
|
|
+
|
|
|
+- (NSArray *)dataArray {
|
|
|
+ if (!_dataArray) {
|
|
|
+ _dataArray = [NSMutableArray array];
|
|
|
+
|
|
|
+ CPDFWatermark *dataWater = [[CPDFWatermark alloc] init];
|
|
|
+
|
|
|
+ NSArray *waterArray = [_document watermarks];
|
|
|
+
|
|
|
+ for (NSInteger i = 0; i < waterArray.count; i++) {
|
|
|
+ CPDFDataModel *dataModel = [[CPDFDataModel alloc] init];
|
|
|
+ dataWater = waterArray[i];
|
|
|
+ dataModel.text = dataWater.text;
|
|
|
+ dataModel.textColor = dataWater.textColor;
|
|
|
+ dataModel.watermarkScale = dataWater.scale;
|
|
|
+ dataModel.watermarkOpacity = dataWater.opacity;
|
|
|
+ dataModel.watermarkRotation = dataWater.rotation;
|
|
|
+
|
|
|
+ [_dataArray addObject:dataModel];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return _dataArray;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - UITableViewDataSource
|
|
|
+
|
|
|
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
+ return self.dataArray.count;
|
|
|
+}
|
|
|
+
|
|
|
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ static NSString *path = @"AddWater";
|
|
|
+
|
|
|
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:path];
|
|
|
+
|
|
|
+ if (!cell) {
|
|
|
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:path];
|
|
|
+ }
|
|
|
+
|
|
|
+ cell.textLabel.text = [self.dataArray[indexPath.row] text];
|
|
|
+ return cell;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Actons
|
|
|
|
|
|
- (void)onClickedDoneBtn {
|
|
@@ -195,6 +257,29 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)editClick {
|
|
|
+ if (self.editView.center.x < 50) {
|
|
|
+ [_editView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.equalTo(self.view.mas_left);
|
|
|
+ make.top.equalTo(self.textViewController.textPreview.mas_top);
|
|
|
+ make.bottom.equalTo(self.textViewController.textPreview.mas_bottom);
|
|
|
+ make.width.mas_equalTo(150);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
|
|
|
+ self.editView.center = CGPointMake(self.editView.center.x + 150, self.editView.center.y);
|
|
|
+ } completion:nil];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)cancelClick {
|
|
|
+ if (self.editView.center.x > 0) {
|
|
|
+ [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
|
|
|
+ self.editView.center = CGPointMake(self.editView.center.x - 150, self.editView.center.y);
|
|
|
+ } completion:nil];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Orientation
|
|
|
|
|
|
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|