PDFBatesAddViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. //
  2. // BatesAddViewController.m
  3. // PDFViewer
  4. //
  5. // Created by kdanmobile_2 on 2022/11/18.
  6. //
  7. #import "PDFBatesAddViewController.h"
  8. #import "PDFAddViewControllerHeader.h"
  9. @interface PDFBatesAddViewController ()
  10. @property (nonatomic,strong) PDFHeaderFooterTextTableView *fontName;
  11. @property (nonatomic,strong) NSMutableArray *dataArray;
  12. @property (nonatomic,strong) PDFBatesAddView *batesAddView;
  13. @end
  14. @implementation PDFBatesAddViewController
  15. #pragma mark - UIViewController Methods
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. [self initExtendEvent];
  20. }
  21. #pragma mark - Initializers
  22. - (void)initNavigation {
  23. self.navigationItem.title = NSLocalizedString(@"Add Bates", nil);
  24. self.navigationController.toolbarHidden = YES;
  25. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneBatesClick:)];
  26. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelClick:)];
  27. }
  28. - (void)initModel {
  29. self.modelData = [[PDFHeaderFooterModel alloc] init];
  30. self.modelData.fontName = @"Helvetica";
  31. self.modelData.fontPosition = 0;
  32. self.modelData.fontText = @"#2#1#0#0";
  33. self.modelData.fontColor = [UIColor blackColor];
  34. }
  35. - (void)initBttonmView {
  36. _batesAddView = [[PDFBatesAddView alloc] init];
  37. [_batesAddView setText];
  38. [self.view addSubview:_batesAddView];
  39. self.headView.preLabel.text = @"0010";
  40. if (([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) || ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) || ([UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) || (self.view.frame.size.width > self.view.frame.size.height)) {
  41. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  42. make.top.equalTo(self.view.mas_top).offset(15);
  43. make.left.equalTo(self.view.mas_left).offset(self.view.frame.size.width / 2);
  44. make.width.mas_equalTo(393);
  45. make.bottom.equalTo(self.view.mas_bottom).offset(- 34);
  46. }];
  47. } else {
  48. [self.batesAddView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.equalTo(self.headView.mas_bottom).offset(26);
  50. make.left.equalTo(self.view.mas_left);
  51. make.width.mas_equalTo(self.view.frame.size.width);
  52. make.bottom.equalTo(self.view).offset(-34);
  53. }];
  54. }
  55. self.batesAddView.localSegment.selectedSegmentIndex = 0;
  56. self.batesAddView.aligbmentSegment.selectedSegmentIndex = 0;
  57. }
  58. - (void)initBasicEvent {
  59. [_batesAddView.localSegment addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventValueChanged];
  60. [_batesAddView.aligbmentSegment addTarget:self action:@selector(changeAligbment:) forControlEvents:UIControlEventValueChanged];
  61. [_batesAddView.colorSlider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];
  62. }
  63. - (void)initExtendEvent {
  64. [_batesAddView.pageIndexNumberText addTarget:self action:@selector(changePageStart:) forControlEvents:UIControlEventEditingChanged];
  65. [_batesAddView.pageNumberText addTarget:self action:@selector(changeText:) forControlEvents:UIControlEventEditingChanged];
  66. [_batesAddView.pageNumberText addTarget:self action:@selector(PDFBatesAddViewUp) forControlEvents:UIControlEventEditingDidBegin];
  67. [_batesAddView.pageIndexNumberText addTarget:self action:@selector(PDFBatesAddViewUp) forControlEvents:UIControlEventEditingDidBegin];
  68. [_batesAddView.pageNumberText addTarget:self action:@selector(PDFBatesAddViewDown) forControlEvents:UIControlEventEditingDidEnd];
  69. [_batesAddView.pageIndexNumberText addTarget:self action:@selector(PDFBatesAddViewDown) forControlEvents:UIControlEventEditingDidEnd];
  70. _batesAddView.fontNameText.delegate = self;
  71. }
  72. #pragma mark - Accessors
  73. - (NSArray *)dataArray {
  74. if (!_dataArray) {
  75. _dataArray = [NSMutableArray array];
  76. NSArray *fontNameArray = [[NSArray alloc] initWithObjects:@"Helvetica",@"Arial",@"Arial Rounded MT Bold", @"Arial Unicode MS",@"Courier",nil];
  77. for (int i = 0; i < fontNameArray.count; i++) {
  78. [_dataArray addObject:fontNameArray[i]];
  79. }
  80. }
  81. return _dataArray;
  82. }
  83. #pragma mark - UITextFieldDelegate
  84. - (void)textFieldDidBeginEditing:(UITextField *)textField {
  85. _fontName = [[PDFHeaderFooterTextTableView alloc] initWithTitleName:NSLocalizedString(@"Font Name", nil)];
  86. _fontName.tableView.delegate = self;
  87. _fontName.tableView.dataSource = self;
  88. [self.batesAddView addSubview:self.fontName ];
  89. [self.view bringSubviewToFront:self.fontName];
  90. [_fontName mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.top.equalTo(self.batesAddView.mas_top);
  92. make.left.equalTo(self.batesAddView.mas_left);
  93. make.width.mas_equalTo(393);
  94. make.height.mas_equalTo(400);
  95. }];
  96. // Tableview animation
  97. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  98. self.fontName.center = CGPointMake(self.fontName.center.x - 200 - [UIScreen mainScreen].bounds.size.width / 2, self.fontName.center.y);
  99. } completion:nil];
  100. [self.fontName.okBtn addTarget:self action:@selector(fontNameOk:) forControlEvents:UIControlEventTouchUpInside];
  101. }
  102. - (void)textFieldDidChangeSelection:(UITextField *)textField {
  103. [self.batesAddView addSubview:self.fontName];
  104. [self.view bringSubviewToFront:self.fontName];
  105. [_fontName mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.top.equalTo(self.batesAddView.mas_top);
  107. make.left.equalTo(self.batesAddView.mas_left);
  108. make.width.mas_equalTo(393);
  109. make.height.mas_equalTo(400);
  110. }];
  111. // Tableview animation
  112. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  113. self.fontName.center = CGPointMake(self.fontName.center.x - 200 - [UIScreen mainScreen].bounds.size.width / 2, self.fontName.center.y);
  114. } completion:nil];
  115. }
  116. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  117. return NO;
  118. }
  119. #pragma mark - UITableViewDataSource
  120. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  121. return self.dataArray.count;
  122. }
  123. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  124. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fontName"];
  125. if (cell == nil) {
  126. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"fontName"];
  127. }
  128. cell.textLabel.text = self.dataArray[indexPath.row];
  129. return cell;
  130. }
  131. #pragma mark - UITableViewDelegate
  132. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  133. self.modelData.fontName = self.dataArray[indexPath.row];
  134. self.headView.preLabel.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
  135. }
  136. #pragma mark - Actions
  137. // Done button enable
  138. - (void)doneBatesClick:(UIBarButtonItem *)btn {
  139. if ([self.delegate respondsToSelector:@selector(PDFViewPerformChangBates:)]) {
  140. [self.delegate PDFViewPerformChangBates:self.modelData];
  141. }
  142. [self.navigationController popViewControllerAnimated:YES];
  143. }
  144. // Candel button enable
  145. - (void)cancelClick:(UIBarButtonItem *)btn {
  146. [self.navigationController popViewControllerAnimated:YES];
  147. }
  148. - (void)fontNameOk:(UIButton *)okBtn {
  149. self.batesAddView.fontNameText.text = self.modelData.fontName;
  150. [_fontName removeFromSuperview];
  151. }
  152. #pragma mark - UI Functions
  153. // Get page text for bates's model
  154. - (void)changeText:(UITextField *)text {
  155. NSArray *textArray = [text.text componentsSeparatedByString:@"#"];
  156. NSString *showText = [[NSString alloc] init];
  157. if (text.text.length >= 2) {
  158. int i = [textArray[1] intValue];
  159. for (int j = 0; j < i-1; j++) {
  160. NSString *test = showText;
  161. showText = [NSString stringWithFormat:@"%d%@",0,test];
  162. }
  163. }
  164. if (text.text.length >= 4) {
  165. showText = [NSString stringWithFormat:@"%@%@",showText,textArray[2]];
  166. }
  167. if (text.text.length >= 6) {
  168. showText = [NSString stringWithFormat:@"%@%@",textArray[3],showText];
  169. }
  170. if (text.text.length == 8) {
  171. showText = [NSString stringWithFormat:@"%@%@",showText,textArray[4]];
  172. }
  173. self.headView.preLabel.text = showText;
  174. self.modelData.fontText = text.text;
  175. }
  176. // Get page text start for bates's model
  177. - (void)changePageStart:(UITextField *)text {
  178. int start = [text.text intValue];
  179. self.modelData.pageStart = [NSString stringWithFormat:@"%d",start - 1];
  180. }
  181. - (void)PDFBatesAddViewUp {
  182. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  183. make.top.equalTo(self.view).offset(125);
  184. make.left.equalTo(self.view.mas_left);
  185. make.width.mas_equalTo(self.view.frame.size.width);
  186. make.height.mas_equalTo(self.view.frame.size.height);
  187. }];
  188. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  189. self.batesAddView.center = CGPointMake(self.batesAddView.center.x, self.batesAddView.center.y - 300);
  190. } completion:nil];
  191. }
  192. - (void)PDFBatesAddViewDown {
  193. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  194. make.top.equalTo(self.headView.mas_bottom).offset(26);
  195. make.left.equalTo(self.view.mas_left);
  196. make.width.mas_equalTo(self.view.frame.size.width);
  197. make.bottom.equalTo(self.view.mas_bottom).offset(-34);
  198. }];
  199. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  200. self.batesAddView.center = CGPointMake(self.batesAddView.center.x, self.batesAddView.center.y + 300);
  201. } completion:nil];
  202. }
  203. #pragma mark - Orientation
  204. // When orientation
  205. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  206. if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) {
  207. [self.headView mas_remakeConstraints:^(MASConstraintMaker *make) {
  208. make.top.equalTo(self.view.mas_top).offset((393 / 2) - (self.image.size.height / 18));
  209. make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.image.size.width / 18));
  210. make.width.mas_equalTo(self.image.size.width / 9);
  211. make.height.mas_equalTo(self.image.size.height / 9);
  212. }];
  213. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  214. make.top.equalTo(self.view.mas_top).offset(15);
  215. make.left.equalTo(self.view.mas_left).offset(self.view.frame.size.width / 2 + 200);
  216. make.width.mas_equalTo(393);
  217. make.bottom.equalTo(self.view.mas_bottom).offset(- 34);
  218. }];
  219. } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
  220. [self.headView mas_remakeConstraints:^(MASConstraintMaker *make) {
  221. make.top.equalTo(self.view.mas_top).offset(125);
  222. make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.image.size.width / 18));
  223. make.width.mas_equalTo(self.image.size.width / 9);
  224. make.height.mas_equalTo(self.image.size.height / 9);
  225. }];
  226. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  227. make.top.equalTo(self.headView.mas_bottom).offset(26);
  228. make.left.equalTo(self.view.mas_left);
  229. make.right.equalTo(self.view.mas_right);
  230. make.bottom.equalTo(self.view.mas_bottom).offset(-34);
  231. }];
  232. }
  233. }
  234. @end