CPDFBatesAddViewController.m 12 KB

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