PDFHeaderFooterAddController.m 11 KB

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