PDFBatesAddViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 = @"Add Bates";
  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:@"Font Name"];
  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:^(BOOL finished) {
  100. NSLog(@"completion");
  101. }];
  102. [self.fontName.okBtn addTarget:self action:@selector(fontNameOk:) forControlEvents:UIControlEventTouchUpInside];
  103. }
  104. - (void)textFieldDidChangeSelection:(UITextField *)textField {
  105. [self.batesAddView addSubview:self.fontName];
  106. [self.view bringSubviewToFront:self.fontName];
  107. [_fontName mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.top.equalTo(self.batesAddView.mas_top);
  109. make.left.equalTo(self.batesAddView.mas_left);
  110. make.width.mas_equalTo(393);
  111. make.height.mas_equalTo(400);
  112. }];
  113. // Tableview animation
  114. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  115. self.fontName.center = CGPointMake(self.fontName.center.x - 200 - [UIScreen mainScreen].bounds.size.width / 2, self.fontName.center.y);
  116. } completion:nil];
  117. }
  118. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  119. return NO;
  120. }
  121. #pragma mark - UITableViewDataSource
  122. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  123. return self.dataArray.count;
  124. }
  125. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  126. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pageFormat"];
  127. if (cell == nil) {
  128. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pageFormat"];
  129. }
  130. cell.textLabel.text = self.dataArray[indexPath.row];
  131. return cell;
  132. }
  133. #pragma mark - UITableViewDelegate
  134. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  135. self.modelData.fontName = self.dataArray[indexPath.row];
  136. self.headView.preLabel.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
  137. }
  138. #pragma mark - Actions
  139. // Done button enable
  140. - (void)doneBatesClick:(UIBarButtonItem *)btn {
  141. if ([self.delegate respondsToSelector:@selector(PDFViewPerformChangBates:)]) {
  142. [self.delegate PDFViewPerformChangBates:self.modelData];
  143. }
  144. [self.navigationController popViewControllerAnimated:YES];
  145. }
  146. // Candel button enable
  147. - (void)cancelClick:(UIBarButtonItem *)btn {
  148. [self.navigationController popViewControllerAnimated:YES];
  149. }
  150. - (void)fontNameOk:(UIButton *)okBtn {
  151. self.batesAddView.fontNameText.text = self.modelData.fontName;
  152. [_fontName removeFromSuperview];
  153. }
  154. #pragma mark - UI Functions
  155. // Get page text for bates's model
  156. - (void)changeText:(UITextField *)text {
  157. NSArray *textArray = [text.text componentsSeparatedByString:@"#"];
  158. NSString *showText = [[NSString alloc] init];
  159. if (text.text.length >= 2) {
  160. int i = [textArray[1] intValue];
  161. for (int j = 0; j < i-1; j++) {
  162. NSString *test = showText;
  163. showText = [NSString stringWithFormat:@"%d%@",0,test];
  164. }
  165. }
  166. if (text.text.length >= 4) {
  167. showText = [NSString stringWithFormat:@"%@%@",showText,textArray[2]];
  168. }
  169. if (text.text.length >= 6) {
  170. showText = [NSString stringWithFormat:@"%@%@",textArray[3],showText];
  171. }
  172. if (text.text.length == 8) {
  173. showText = [NSString stringWithFormat:@"%@%@",showText,textArray[4]];
  174. }
  175. self.headView.preLabel.text = showText;
  176. self.modelData.fontText = text.text;
  177. }
  178. // Get page text start for bates's model
  179. - (void)changePageStart:(UITextField *)text {
  180. int start = [text.text intValue];
  181. self.modelData.pageStart = [NSString stringWithFormat:@"%d",start - 1];
  182. }
  183. - (void)PDFBatesAddViewUp {
  184. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  185. make.top.equalTo(self.view).offset(125);
  186. make.left.equalTo(self.view.mas_left);
  187. make.width.mas_equalTo(self.view.frame.size.width);
  188. make.height.mas_equalTo(self.view.frame.size.height);
  189. }];
  190. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  191. self.batesAddView.center = CGPointMake(self.batesAddView.center.x, self.batesAddView.center.y - 300);
  192. } completion:nil];
  193. }
  194. - (void)PDFBatesAddViewDown {
  195. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  196. make.top.equalTo(self.headView.mas_bottom).offset(26);
  197. make.left.equalTo(self.view.mas_left);
  198. make.width.mas_equalTo(self.view.frame.size.width);
  199. make.bottom.equalTo(self.view.mas_bottom).offset(-34);
  200. }];
  201. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  202. self.batesAddView.center = CGPointMake(self.batesAddView.center.x, self.batesAddView.center.y + 300);
  203. } completion:nil];
  204. }
  205. #pragma mark - Orientation
  206. // When orientation
  207. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  208. if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) {
  209. [self.headView mas_remakeConstraints:^(MASConstraintMaker *make) {
  210. make.top.equalTo(self.view.mas_top).offset((393 / 2) - (self.image.size.height / 18));
  211. make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.image.size.width / 18));
  212. make.width.mas_equalTo(self.image.size.width / 9);
  213. make.height.mas_equalTo(self.image.size.height / 9);
  214. }];
  215. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  216. make.top.equalTo(self.view.mas_top).offset(15);
  217. make.left.equalTo(self.view.mas_left).offset(self.view.frame.size.width / 2 + 200);
  218. make.width.mas_equalTo(393);
  219. make.bottom.equalTo(self.view.mas_bottom).offset(- 34);
  220. }];
  221. } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
  222. [self.headView mas_remakeConstraints:^(MASConstraintMaker *make) {
  223. make.top.equalTo(self.view.mas_top).offset(125);
  224. make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.image.size.width / 18));
  225. make.width.mas_equalTo(self.image.size.width / 9);
  226. make.height.mas_equalTo(self.image.size.height / 9);
  227. }];
  228. [self.batesAddView mas_remakeConstraints:^(MASConstraintMaker *make) {
  229. make.top.equalTo(self.headView.mas_bottom).offset(26);
  230. make.left.equalTo(self.view.mas_left);
  231. make.right.equalTo(self.view.mas_right);
  232. make.bottom.equalTo(self.view.mas_bottom).offset(-34);
  233. }];
  234. }
  235. }
  236. @end