CPDFHeaderFooterAddController.m 11 KB

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