|
@@ -11,16 +11,258 @@
|
|
|
//
|
|
|
|
|
|
#import "CPDFStampViewController.h"
|
|
|
+#import "CStampFileManger.h"
|
|
|
+#import "CStampCollectionViewCell.h"
|
|
|
+#import "CPDFColorUtils.h"
|
|
|
+#import "CStampButton.h"
|
|
|
|
|
|
-@interface CPDFStampViewController ()
|
|
|
+#import <ComPDFKit/ComPDFKit.h>
|
|
|
+
|
|
|
+PDFAnnotationStampKey const PDFAnnotationStampKeyType = @"PDFAnnotationStampKeyType";
|
|
|
+PDFAnnotationStampKey const PDFAnnotationStampKeyImagePath = @"PDFAnnotationStampKeyImagePath";
|
|
|
+PDFAnnotationStampKey const PDFAnnotationStampKeyText = @"PDFAnnotationStampKeyText";
|
|
|
+PDFAnnotationStampKey const PDFAnnotationStampKeyShowDate = @"PDFAnnotationStampKeyShowDate";
|
|
|
+PDFAnnotationStampKey const PDFAnnotationStampKeyShowTime = @"PDFAnnotationStampKeyShowTime";
|
|
|
+PDFAnnotationStampKey const PDFAnnotationStampKeyStyle = @"PDFAnnotationStampKeyStyle";
|
|
|
+PDFAnnotationStampKey const PDFAnnotationStampKeyShape = @"PDFAnnotationStampKeyShape";
|
|
|
+
|
|
|
+@interface CPDFStampViewController () <UICollectionViewDelegate, UICollectionViewDataSource>
|
|
|
+
|
|
|
+@property (nonatomic, strong) UICollectionView *collectView;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UISegmentedControl *segmentedControl;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSArray *standardArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSArray *customTextArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSArray *customImageArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSMutableDictionary *imgDicCache;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIButton *backBtn;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UILabel *titleLabel;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIButton *createButton;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIView *standardView;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIView *customizeView;
|
|
|
+
|
|
|
+@property (nonatomic, strong) CStampFileManger *stampFileManager;
|
|
|
+
|
|
|
+@property (nonatomic, strong) CStampButton *textButton;
|
|
|
+
|
|
|
+@property (nonatomic, strong) CStampButton *imageButton;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation CPDFStampViewController
|
|
|
|
|
|
+#pragma mark - ViewController Methods
|
|
|
+
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
// Do any additional setup after loading the view.
|
|
|
+ self.view.backgroundColor = [CPDFColorUtils CPDFViewControllerBackgroundColor];
|
|
|
+
|
|
|
+ self.titleLabel = [[UILabel alloc] init];
|
|
|
+ self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
|
|
|
+ self.titleLabel.text = NSLocalizedString(@"Stamp", nil);
|
|
|
+ self.titleLabel.font = [UIFont systemFontOfSize:20];
|
|
|
+ self.titleLabel.adjustsFontSizeToFitWidth = YES;
|
|
|
+ [self.view addSubview:self.titleLabel];
|
|
|
+
|
|
|
+ self.backBtn = [[UIButton alloc] init];
|
|
|
+ self.backBtn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
|
|
|
+ [self.backBtn setImage:[UIImage imageNamed:@"CPDFAnnotationBaseImageBack" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
+ [self.backBtn addTarget:self action:@selector(buttonItemClicked_back:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [self.view addSubview:self.backBtn];
|
|
|
+
|
|
|
+ NSArray *segmmentArray = [NSArray arrayWithObjects:NSLocalizedString(@"Standard", nil), NSLocalizedString(@"Customize", nil), nil];
|
|
|
+ self.segmentedControl = [[UISegmentedControl alloc] initWithItems:segmmentArray];
|
|
|
+ self.segmentedControl.selectedSegmentIndex = 0;
|
|
|
+ self.segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
+ [self.segmentedControl addTarget:self action:@selector(segmentedControlValueChanged_singature:) forControlEvents:UIControlEventValueChanged];
|
|
|
+ [self.view addSubview:self.segmentedControl];
|
|
|
+
|
|
|
+ // StandardView
|
|
|
+ [self createStandardView];
|
|
|
+
|
|
|
+ // CustomizeView
|
|
|
+ [self createCustomizeView];
|
|
|
+
|
|
|
+ // Data
|
|
|
+ NSMutableArray *array = [NSMutableArray array];
|
|
|
+ for (int i=1; i<13; i++) {
|
|
|
+ NSString *tPicName = nil;
|
|
|
+ if (i<10) {
|
|
|
+ tPicName = [NSString stringWithFormat:@"CPDFStampImage-0%d.png",i];
|
|
|
+ } else {
|
|
|
+ tPicName = [NSString stringWithFormat:@"CPDFStampImage-%d.png",i];
|
|
|
+ }
|
|
|
+ [array addObject:tPicName];
|
|
|
+ }
|
|
|
+ [array addObjectsFromArray:@[@"CPDFStampImage-13", @"CPDFStampImage-14", @"CPDFStampImage-15", @"CPDFStampImage-16", @"CPDFStampImage-18", @"CPDFStampImage-20", @"CPDFStampImage_chick", @"CPDFStampImage_cross", @"CPDFStampImage_circle"]];
|
|
|
+ self.standardArray = array;
|
|
|
+ self.imgDicCache = [NSMutableDictionary dictionary];
|
|
|
+
|
|
|
+ self.stampFileManager = [[CStampFileManger alloc] init];
|
|
|
+ [self.stampFileManager readStampDataFromFile];
|
|
|
+ self.customTextArray = [self.stampFileManager getTextStampData];
|
|
|
+ self.customImageArray = [self.stampFileManager getImageStampData];
|
|
|
+
|
|
|
+ [self createGestureRecognizer];
|
|
|
+ [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewWillLayoutSubviews {
|
|
|
+ [super viewWillLayoutSubviews];
|
|
|
+ self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, 50);
|
|
|
+ self.segmentedControl.frame = CGRectMake(50, 50, self.view.frame.size.width-100, 30);
|
|
|
+
|
|
|
+ if (@available(iOS 11.0, *)) {
|
|
|
+ self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60 - self.view.safeAreaInsets.right, 5, 50, 50);
|
|
|
+ self.createButton.frame = CGRectMake(self.view.frame.size.width - 70 - self.view.safeAreaInsets.right, self.view.frame.size.height - 200 - self.view.safeAreaInsets.bottom, 50, 50);
|
|
|
+ } else {
|
|
|
+ self.backBtn.frame = CGRectMake(self.view.frame.size.width - 100, 5, 50, 50);
|
|
|
+ self.createButton.frame = CGRectMake(self.view.frame.size.width - 70, self.view.frame.size.height - 100, 50, 50);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewWillAppear:(BOOL)animated {
|
|
|
+ [super viewWillAppear:animated];
|
|
|
+
|
|
|
+ [self.collectView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
|
|
+ [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
|
|
|
+ [self updatePreferredContentSizeWithTraitCollection:newCollection];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - Private Methods
|
|
|
+
|
|
|
+- (void)createStandardView {
|
|
|
+ self.standardView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height)];
|
|
|
+ self.standardView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
|
|
|
+ [self.view addSubview:self.standardView];
|
|
|
+
|
|
|
+ UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
|
+ layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
|
+ layout.minimumInteritemSpacing = 10;
|
|
|
+ layout.minimumLineSpacing = 10;
|
|
|
+ layout.itemSize = CGSizeMake(170,80);
|
|
|
+ layout.sectionInset = UIEdgeInsetsMake(5, 20, 5, 20);
|
|
|
+
|
|
|
+ self.collectView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
|
|
|
+ self.collectView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
|
|
|
+ self.collectView.delegate = self;
|
|
|
+ self.collectView.dataSource = self;
|
|
|
+ self.collectView.backgroundColor = [UIColor clearColor];
|
|
|
+ [self.collectView registerClass:[StampCollectionHeaderView class]
|
|
|
+ forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
|
|
|
+ withReuseIdentifier:@"header"];
|
|
|
+ [self.collectView registerClass:[StampCollectionHeaderView1 class]
|
|
|
+ forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
|
|
|
+ withReuseIdentifier:@"header1"];
|
|
|
+ [self.collectView registerClass:[CStampCollectionViewCell class]
|
|
|
+ forCellWithReuseIdentifier:@"TStampViewCell"];
|
|
|
+
|
|
|
+ if (@available(iOS 11.0, *)) {
|
|
|
+ _collectView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
|
|
|
+ }
|
|
|
+ [self.standardView addSubview:self.collectView];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)createCustomizeView {
|
|
|
+ self.customizeView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height)];
|
|
|
+ self.customizeView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
|
|
|
+ [self.view addSubview:self.customizeView];
|
|
|
+ self.customizeView.hidden = YES;
|
|
|
+
|
|
|
+ self.createButton = [[UIButton alloc] init];
|
|
|
+ self.createButton.layer.cornerRadius = 25.0;
|
|
|
+ self.createButton.clipsToBounds = YES;
|
|
|
+ [self.createButton setImage:[UIImage imageNamed:@"CPDFSignatureImageAdd" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
+ self.createButton.backgroundColor = [UIColor blueColor];
|
|
|
+ [self.createButton addTarget:self action:@selector(buttonItemClicked_create:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [self.customizeView addSubview:self.createButton];
|
|
|
+
|
|
|
+ self.textButton = [[CStampButton alloc] init];
|
|
|
+ [self.textButton.stampBtn setImage:[UIImage imageNamed:@"CPDFStampImageText" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
+ self.textButton.titleLabel.text = NSLocalizedString(@"", nil);
|
|
|
+ [self.textButton.stampBtn addTarget:self action:@selector(buttonItemClicked_text:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [self.customizeView addSubview:self.textButton];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)createGestureRecognizer {
|
|
|
+ [self.createButton setUserInteractionEnabled:YES];
|
|
|
+
|
|
|
+ UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panaddBookmarkBtn:)];
|
|
|
+ [self.createButton addGestureRecognizer:panRecognizer];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)panaddBookmarkBtn:(UIPanGestureRecognizer *)gestureRecognizer {
|
|
|
+ CGPoint point = [gestureRecognizer translationInView:self.view];
|
|
|
+ CGFloat newX = self.createButton.center.x + point.x;
|
|
|
+ CGFloat newY = self.createButton.center.y + point.y;
|
|
|
+ if (CGRectContainsPoint(self.view.frame, CGPointMake(newX, newY))) {
|
|
|
+ self.createButton.center = CGPointMake(newX, newY);
|
|
|
+ }
|
|
|
+ [gestureRecognizer setTranslation:CGPointZero inView:self.view];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - Protect Methods
|
|
|
+
|
|
|
+- (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
|
|
|
+ self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 370 : 800);
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - Action
|
|
|
+
|
|
|
+- (void)buttonItemClicked_back:(id)sender {
|
|
|
+ [self dismissViewControllerAnimated:YES completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)buttonItemClicked_create:(id)sender {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)segmentedControlValueChanged_singature:(id)sender {
|
|
|
+ if (self.segmentedControl.selectedSegmentIndex == 0) {
|
|
|
+ self.standardView.hidden = NO;
|
|
|
+ self.customizeView.hidden = YES;
|
|
|
+ } else {
|
|
|
+ self.standardView.hidden = YES;
|
|
|
+ self.customizeView.hidden = NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)buttonItemClicked_text:(id)sender {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)buttonItemClicked_image:(id)sender {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - UICollectionViewDataSource
|
|
|
+
|
|
|
+- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
|
+ return self.standardArray.count;
|
|
|
+}
|
|
|
+
|
|
|
+- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ CStampCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TStampViewCell" forIndexPath:indexPath];
|
|
|
+ cell.editing = NO;
|
|
|
+ cell.stampImage.image = [UIImage imageNamed:self.standardArray[indexPath.item] inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
|
|
|
+ return cell;
|
|
|
}
|
|
|
|
|
|
@end
|