CPDFPDFInsertViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. //
  2. // CPDFPDFInsertViewController.m
  3. // compdfkit-tools
  4. //
  5. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  6. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  7. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  8. // This notice may not be removed from this file.
  9. //
  10. #import "CPDFPDFInsertViewController.h"
  11. #import "CPDFColorUtils.h"
  12. #import "CInsertBlankPageCell.h"
  13. #import "CBlankPageModel.h"
  14. #import <ComPDFKit/ComPDFKit.h>
  15. @interface CPDFPDFInsertViewController () <UITableViewDelegate, UITableViewDataSource, CInsertBlankPageCellDelegate>
  16. @property (nonatomic, strong) UIButton *cancelBtn;
  17. @property (nonatomic, strong) UIButton *saveButton;
  18. @property (nonatomic, strong) UIView *headerView;
  19. @property (nonatomic, strong) UILabel *titleLabel;
  20. @property (nonatomic, strong) UITableView *tableView;
  21. @property (nonatomic, strong) NSArray *dataArray;
  22. @property (nonatomic, assign) BOOL isSelect;
  23. @property (nonatomic, strong) CPDFDocument *document;
  24. @property (nonatomic, strong) UIButton *selectRangeBtn;
  25. @property (nonatomic, strong) CInsertBlankPageCell *rangePreCell;
  26. @property (nonatomic, strong) UIButton *selectLocationBtn;
  27. @property (nonatomic, strong) CInsertBlankPageCell *locationPreCell;
  28. @property (nonatomic, strong) NSMutableArray *pageLoactionBtns;
  29. @property (nonatomic, strong) NSMutableArray *pageRangeBtns;
  30. @property (nonatomic, strong) CBlankPageModel *pageModel;
  31. @property (nonatomic, strong) UITextField *locationTextField;
  32. @property (nonatomic, strong) UITextField *rangeTextField;
  33. @property (nonatomic, assign) CPDFPDFInsertType pdfInsertType;
  34. @end
  35. @implementation CPDFPDFInsertViewController
  36. #pragma mark - Initializers
  37. - (instancetype)initWithDocument:(CPDFDocument *)document {
  38. if (self = [super init]) {
  39. self.document = document;
  40. }
  41. return self;
  42. }
  43. #pragma mark - Accessors
  44. - (NSArray *)dataArray {
  45. if (!_dataArray) {
  46. NSArray *dataArray = @[NSLocalizedString(@"Font Name", nil), NSLocalizedString(@"Page Range", nil), NSLocalizedString(@"All Page", nil), NSLocalizedString(@"Odd number", nil), NSLocalizedString(@"Even number", nil), NSLocalizedString(@"Specify page", nil), NSLocalizedString(@"for example:1,3-5,10", nil), NSLocalizedString(@"Page Location", nil),NSLocalizedString(@"Home page", nil), NSLocalizedString(@"Last page", nil), NSLocalizedString(@"Insert before specifiled page", nil), NSLocalizedString(@"Please enter a page", nil), NSLocalizedString(@"Insert after specifiled page", nil)];
  47. _dataArray = dataArray;
  48. }
  49. return _dataArray;
  50. }
  51. #pragma mark - ViewController Methods
  52. - (void)viewDidLoad {
  53. [super viewDidLoad];
  54. // Do any additional setup after loading the view.
  55. self.headerView = [[UIView alloc] init];
  56. self.headerView.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
  57. self.headerView.layer.borderWidth = 1.0;
  58. self.headerView.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  59. [self.view addSubview:self.headerView];
  60. self.titleLabel = [[UILabel alloc] init];
  61. self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  62. self.titleLabel.text = NSLocalizedString(@"Insert PDF page", nil);
  63. self.titleLabel.textAlignment = NSTextAlignmentCenter;
  64. self.titleLabel.font = [UIFont systemFontOfSize:20];
  65. self.titleLabel.adjustsFontSizeToFitWidth = YES;
  66. [self.headerView addSubview:self.titleLabel];
  67. self.saveButton = [[UIButton alloc] init];
  68. self.saveButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  69. [self.saveButton setTitle:NSLocalizedString(@"Save", nil) forState:UIControlStateNormal];
  70. [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
  71. [self.saveButton addTarget:self action:@selector(buttonItemClicked_save:) forControlEvents:UIControlEventTouchUpInside];
  72. [self.headerView addSubview:self.saveButton];
  73. self.cancelBtn = [[UIButton alloc] init];
  74. self.cancelBtn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  75. self.cancelBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
  76. [self.cancelBtn setTitle:NSLocalizedString(@"Cancel", nil) forState:UIControlStateNormal];
  77. [self.cancelBtn setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
  78. [self.cancelBtn addTarget:self action:@selector(buttonItemClicked_cancel:) forControlEvents:UIControlEventTouchUpInside];
  79. [self.headerView addSubview:self.cancelBtn];
  80. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-50) style:UITableViewStylePlain];
  81. self.tableView.delegate = self;
  82. self.tableView.dataSource = self;
  83. self.tableView.rowHeight = 60.0;
  84. self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  85. self.tableView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
  86. [self.view addSubview:self.tableView];
  87. self.isSelect = NO;
  88. self.view.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  89. self.pageModel = [[CBlankPageModel alloc] init];
  90. self.pageModel.pageIndex = 0;
  91. self.pageModel.rotation = 0;
  92. NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
  93. for (int i = 0; i < self.document.pageCount; i++) {
  94. [indexSet addIndex:i];
  95. }
  96. self.pageModel.indexSet = indexSet;
  97. self.pageLoactionBtns = [NSMutableArray array];
  98. self.pageRangeBtns = [NSMutableArray array];
  99. [[NSNotificationCenter defaultCenter] addObserver:self
  100. selector:@selector(keyboardwillChangeFrame:)
  101. name:UIKeyboardWillChangeFrameNotification
  102. object:nil];
  103. [[NSNotificationCenter defaultCenter] addObserver:self
  104. selector:@selector(keyboardWillHide:)
  105. name:UIKeyboardWillHideNotification
  106. object:nil];
  107. }
  108. - (void)viewWillLayoutSubviews {
  109. [super viewWillLayoutSubviews];
  110. self.headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, 50);
  111. self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 200)/2, 0, 200, 50);
  112. if (@available(iOS 11.0, *)) {
  113. self.saveButton.frame = CGRectMake(self.view.frame.size.width - 60 - self.view.safeAreaInsets.right, 5, 50, 40);
  114. self.cancelBtn.frame = CGRectMake( self.view.safeAreaInsets.left+20, 5, 50, 40);
  115. } else {
  116. self.saveButton.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 40);
  117. self.cancelBtn.frame = CGRectMake(20, 5, 50, 40);
  118. }
  119. }
  120. #pragma mark - Private Methods
  121. - (void)popoverWarning {
  122. UIAlertAction *OKAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
  123. style:UIAlertActionStyleDefault
  124. handler:^(UIAlertAction *action) {
  125. }];
  126. UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Warning", nil)
  127. message:NSLocalizedString(@"Sorry,out of page scope", nil)
  128. preferredStyle:UIAlertControllerStyleAlert];
  129. [alert addAction:OKAction];
  130. [self presentViewController:alert animated:YES completion:nil];
  131. }
  132. - (NSString *)stringByTruncatingMiddleWithFont:(UIFont *)font maxLength:(CGFloat)maxLength {
  133. if ([[self.document.documentURL lastPathComponent] sizeWithAttributes:@{NSFontAttributeName: font}].width <= maxLength) {
  134. return [self.document.documentURL lastPathComponent];
  135. }
  136. NSInteger halfLength = ([self.document.documentURL lastPathComponent].length) / 4;
  137. NSString *firstHalf = [[self.document.documentURL lastPathComponent] substringToIndex:halfLength];
  138. NSString *secondHalf = [[self.document.documentURL lastPathComponent] substringFromIndex:[self.document.documentURL lastPathComponent].length - halfLength];
  139. NSString *truncatedStr = [NSString stringWithFormat:@"%@...%@", firstHalf, secondHalf];
  140. return truncatedStr;
  141. }
  142. #pragma mark - Action
  143. - (void)buttonItemClicked_save:(id)sender {
  144. [self dismissViewControllerAnimated:YES completion:^{
  145. if (self.delegate && [self.delegate respondsToSelector:@selector(pdfInsertViewControllerSave:pageModel:)]) {
  146. [self.delegate pdfInsertViewControllerSave:self pageModel:self.pageModel];
  147. }
  148. }];
  149. }
  150. - (void)buttonItemClicked_cancel:(id)sender {
  151. [self dismissViewControllerAnimated:YES completion:^{
  152. if (self.delegate && [self.delegate respondsToSelector:@selector(pdfInsertViewControllerCancel:)]) {
  153. [self.delegate pdfInsertViewControllerCancel:self];
  154. }
  155. }];
  156. }
  157. #pragma mark - UITableViewDataSource
  158. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  159. return self.dataArray.count;
  160. }
  161. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  162. CInsertBlankPageCell *cell = [[CInsertBlankPageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"pageCell"];
  163. cell.delegate = self;
  164. switch (indexPath.row) {
  165. case 0:
  166. {
  167. [cell setCellStyle:CInsertBlankPageCellSize label:self.dataArray[indexPath.row]];
  168. CGFloat maxLength = 200.0;
  169. UIFont *font = [UIFont systemFontOfSize:18.0];
  170. cell.sizeLabel.text = [self stringByTruncatingMiddleWithFont:font maxLength:maxLength];
  171. }
  172. break;
  173. case 1:
  174. [cell setCellStyle:CInsertBlankPageCellLocation label:self.dataArray[indexPath.row]];
  175. break;
  176. case 2:
  177. {
  178. [cell setCellStyle:CInsertBlankPageCellRangeSelect label:self.dataArray[indexPath.row]];
  179. if (![self.pageRangeBtns containsObject:cell.rangeSelectBtn]) {
  180. [self.pageRangeBtns addObject:cell.rangeSelectBtn];
  181. }
  182. self.rangePreCell = cell;
  183. cell.rangeSelectBtn.selected = !cell.rangeSelectBtn.selected;
  184. cell.rangeSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  185. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  186. }
  187. break;
  188. case 3 ... 5:
  189. {
  190. [cell setCellStyle:CInsertBlankPageCellRangeSelect label:self.dataArray[indexPath.row]];
  191. if (![self.pageRangeBtns containsObject:cell.rangeSelectBtn]) {
  192. [self.pageRangeBtns addObject:cell.rangeSelectBtn];
  193. }
  194. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  195. }
  196. break;
  197. case 6:
  198. [cell setCellStyle:CInsertBlankPageCellRangeTextFiled label:self.dataArray[indexPath.row]];
  199. break;
  200. case 7:
  201. [cell setCellStyle:CInsertBlankPageCellLocation label:self.dataArray[indexPath.row]];
  202. break;
  203. case 8:
  204. {
  205. [cell setCellStyle:CInsertBlankPageCellLocationSelect label:self.dataArray[indexPath.row]];
  206. if (![self.pageLoactionBtns containsObject:cell.locationSelectBtn]) {
  207. [self.pageLoactionBtns addObject:cell.locationSelectBtn];
  208. }
  209. if (!self.currentPageIndex) {
  210. self.locationPreCell = cell;
  211. cell.locationSelectBtn.selected = !cell.locationSelectBtn.selected;
  212. cell.locationSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  213. }
  214. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  215. }
  216. break;
  217. case 9:
  218. {
  219. [cell setCellStyle:CInsertBlankPageCellLocationSelect label:self.dataArray[indexPath.row]];
  220. if (![self.pageLoactionBtns containsObject:cell.locationSelectBtn]) {
  221. [self.pageLoactionBtns addObject:cell.locationSelectBtn];
  222. }
  223. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  224. }
  225. break;
  226. case 10:
  227. {
  228. [cell setCellStyle:CInsertBlankPageCellLocationSelect label:self.dataArray[indexPath.row]];
  229. if (![self.pageLoactionBtns containsObject:cell.locationSelectBtn]) {
  230. [self.pageLoactionBtns addObject:cell.locationSelectBtn];
  231. }
  232. if (self.currentPageIndex) {
  233. self.locationPreCell = cell;
  234. cell.locationSelectBtn.selected = !cell.locationSelectBtn.selected;
  235. cell.locationSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  236. }
  237. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  238. }
  239. break;
  240. case 11:
  241. {
  242. [cell setCellStyle:CInsertBlankPageCellLocationTextFiled label:self.dataArray[indexPath.row]];
  243. if (self.currentPageIndex) {
  244. cell.locationTextField.text = [NSString stringWithFormat:@"%lu", self.currentPageIndex];
  245. self.pageModel.pageIndex = self.currentPageIndex-1;
  246. }
  247. self.locationTextField = cell.locationTextField;
  248. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  249. }
  250. break;
  251. case 12:
  252. {
  253. [cell setCellStyle:CInsertBlankPageCellLocationSelect label:self.dataArray[indexPath.row]];
  254. if (![self.pageLoactionBtns containsObject:cell.locationSelectBtn]) {
  255. [self.pageLoactionBtns addObject:cell.locationSelectBtn];
  256. }
  257. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  258. }
  259. break;
  260. default:
  261. break;
  262. }
  263. return cell;
  264. }
  265. #pragma mark - CInsertBlankPageCellDelegate
  266. - (void)insertBlankPageCellRange:(CInsertBlankPageCell *)insertBlankPageCell button:(UIButton *)buttom {
  267. if (self.rangePreCell) {
  268. self.rangePreCell.rangeSelectBtn.selected = !self.rangePreCell.rangeSelectBtn.selected;
  269. self.rangePreCell.rangeSelectLabel.textColor = [UIColor grayColor];
  270. if (self.rangePreCell.rangeSelectBtn != buttom) {
  271. buttom.selected = !buttom.selected;
  272. insertBlankPageCell.rangeSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  273. self.rangePreCell = insertBlankPageCell;
  274. } else {
  275. self.rangePreCell.rangeSelectLabel.textColor = [UIColor grayColor];
  276. self.rangePreCell = nil;
  277. }
  278. } else {
  279. self.rangePreCell = insertBlankPageCell;
  280. buttom.selected = !buttom.selected;
  281. insertBlankPageCell.rangeSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  282. }
  283. NSInteger range = [self.pageRangeBtns indexOfObject:buttom];
  284. switch (range) {
  285. case 0:
  286. {
  287. NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
  288. for (int i = 0; i < self.document.pageCount; i++) {
  289. [indexSet addIndex:i];
  290. }
  291. self.pageModel.indexSet = indexSet;
  292. self.rangeTextField.userInteractionEnabled = NO;
  293. }
  294. break;
  295. case 1:
  296. {
  297. NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
  298. for (int i = 0; i < self.document.pageCount; i += 2) {
  299. [indexSet addIndex:i];
  300. }
  301. self.pageModel.indexSet = indexSet;
  302. self.rangeTextField.userInteractionEnabled = NO;
  303. }
  304. break;
  305. case 2:
  306. {
  307. NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
  308. for (int i = 1; i < self.document.pageCount; i += 2) {
  309. [indexSet addIndex:i];
  310. }
  311. self.pageModel.indexSet = indexSet;
  312. self.rangeTextField.userInteractionEnabled = NO;
  313. }
  314. break;
  315. case 4:
  316. self.rangeTextField.userInteractionEnabled = YES;
  317. break;
  318. default:
  319. break;
  320. }
  321. }
  322. - (void)insertBlankPageCellLocation:(CInsertBlankPageCell *)insertBlankPageCell button:(UIButton *)buttom {
  323. if (self.locationPreCell) {
  324. self.locationPreCell.locationSelectBtn.selected = !self.locationPreCell.locationSelectBtn.selected;
  325. self.locationPreCell.locationSelectLabel.textColor = [UIColor grayColor];
  326. if (self.locationPreCell.locationSelectBtn != buttom) {
  327. buttom.selected = !buttom.selected;
  328. insertBlankPageCell.locationSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  329. self.locationPreCell = insertBlankPageCell;
  330. } else {
  331. self.locationPreCell.locationSelectLabel.textColor = [UIColor grayColor];
  332. self.locationPreCell = nil;
  333. }
  334. } else {
  335. self.locationPreCell = insertBlankPageCell;
  336. buttom.selected = !buttom.selected;
  337. insertBlankPageCell.locationSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  338. }
  339. NSInteger location = [self.pageLoactionBtns indexOfObject:buttom];
  340. switch (location) {
  341. case 0:
  342. self.pageModel.pageIndex = 0;
  343. self.pdfInsertType = CPDFPDFInsertTypeNone;
  344. break;
  345. case 1:
  346. self.pageModel.pageIndex = -2;
  347. self.pdfInsertType = CPDFPDFInsertTypeNone;
  348. break;
  349. case 2:
  350. self.pdfInsertType = CPDFPDFInsertTypeBefore;
  351. break;
  352. case 3:
  353. self.pdfInsertType = CPDFPDFInsertTypeAfter;
  354. break;
  355. default:
  356. break;
  357. }
  358. }
  359. - (void)insertBlankPageCell:(CInsertBlankPageCell *)insertBlankPageCell pageRange:(NSString *)pageRange {
  360. NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
  361. if ([pageRange containsString:@","]) {
  362. NSArray<NSString *> *pageIndexsArray = [pageRange componentsSeparatedByString:@","];
  363. for (NSString *pageIndexStr in pageIndexsArray) {
  364. if ([pageIndexStr containsString:@"-"]) {
  365. NSArray<NSString *> *pageIndexs = [pageIndexStr componentsSeparatedByString:@"-"];
  366. NSInteger start = [pageIndexs[0] integerValue];
  367. NSInteger end = [pageIndexs[1] integerValue];
  368. if (end > self.document.pageCount-1) {
  369. [self popoverWarning];
  370. } else {
  371. for (NSInteger i = start-1; i <= end-1; i++) {
  372. [indexSet addIndex:i];
  373. }
  374. }
  375. } else {
  376. if ([pageIndexStr integerValue] > self.document.pageCount-1) {
  377. [self popoverWarning];
  378. } else {
  379. [indexSet addIndex:[pageIndexStr integerValue]-1];
  380. }
  381. }
  382. }
  383. } else {
  384. if ([pageRange containsString:@"-"]) {
  385. NSArray<NSString *> *pageIndexs = [pageRange componentsSeparatedByString:@"-"];
  386. NSInteger start = [pageIndexs[0] integerValue];
  387. NSInteger end = [pageIndexs[1] integerValue];
  388. if (end > self.document.pageCount-1) {
  389. [self popoverWarning];
  390. } else {
  391. for (NSInteger i = start-1; i <= end-1; i++) {
  392. [indexSet addIndex:i];
  393. }
  394. }
  395. } else {
  396. if ([pageRange integerValue] > self.document.pageCount-1) {
  397. [self popoverWarning];
  398. } else {
  399. [indexSet addIndex:[pageRange integerValue]-1];
  400. }
  401. }
  402. }
  403. self.pageModel.indexSet = indexSet;
  404. }
  405. - (void)insertBlankPageCell:(CInsertBlankPageCell *)insertBlankPageCell pageIndex:(NSInteger)pageIndex {
  406. self.pageModel.pageIndex = pageIndex-1;
  407. if (self.pdfInsertType == CPDFPDFInsertTypeBefore) {
  408. self.pageModel.pageIndex = self.pageModel.pageIndex - 1;
  409. } else if (self.pdfInsertType == CPDFPDFInsertTypeAfter) {
  410. self.pageModel.pageIndex = self.pageModel.pageIndex + 1;
  411. }
  412. }
  413. - (void)insertBlankPageCellLocationTextFieldBegin:(CInsertBlankPageCell *)insertBlankPageCell {
  414. for (UIButton *button in self.pageLoactionBtns) {
  415. NSInteger location = [self.pageLoactionBtns indexOfObject:button];
  416. switch (location) {
  417. case 0 ... 1:
  418. if (button.selected) {
  419. self.locationPreCell.locationSelectBtn.selected = !self.locationPreCell.locationSelectBtn.selected;
  420. self.locationPreCell.locationSelectLabel.textColor = [UIColor grayColor];
  421. }
  422. break;
  423. case 2:
  424. if (!button.selected && !((UIButton *)self.pageLoactionBtns[3]).selected) {
  425. self.pdfInsertType = CPDFPDFInsertTypeBefore;
  426. CInsertBlankPageCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:10 inSection:0]];
  427. cell.locationSelectBtn.selected = !cell.locationSelectBtn.selected;
  428. cell.locationSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  429. self.locationPreCell = cell;
  430. }
  431. break;
  432. default:
  433. break;
  434. }
  435. }
  436. }
  437. - (void)insertBlankPageCellRangeTextFieldBegin:(CInsertBlankPageCell *)insertBlankPageCell {
  438. for (UIButton *button in self.pageRangeBtns) {
  439. NSInteger location = [self.pageRangeBtns indexOfObject:button];
  440. switch (location) {
  441. case 0 ... 2:
  442. if (button.selected) {
  443. self.rangePreCell.rangeSelectBtn.selected = !self.rangePreCell.rangeSelectBtn.selected;
  444. self.rangePreCell.locationSelectLabel.textColor = [UIColor grayColor];
  445. }
  446. break;
  447. case 3:
  448. if (!button.selected) {
  449. CInsertBlankPageCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:5 inSection:0]];
  450. cell.rangeSelectBtn.selected = !cell.rangeSelectBtn.selected;
  451. cell.rangeSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  452. self.rangePreCell = cell;
  453. }
  454. break;
  455. default:
  456. break;
  457. }
  458. }
  459. }
  460. #pragma mark - NSNotification
  461. - (void)keyboardwillChangeFrame:(NSNotification *)notification {
  462. NSDictionary *userInfo = [notification userInfo];
  463. NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  464. CGRect frame = value.CGRectValue;
  465. CGRect rect = [self.locationTextField convertRect:self.locationTextField.frame toView:self.view];
  466. if(CGRectGetMaxY(rect) > self.view.frame.size.height - frame.size.height) {
  467. UIEdgeInsets insets = self.tableView.contentInset;
  468. insets.bottom = frame.size.height + self.locationTextField.frame.size.height;
  469. self.tableView.contentInset = insets;
  470. }
  471. }
  472. - (void)keyboardWillHide:(NSNotification *)notification {
  473. UIEdgeInsets insets = self.tableView.contentInset;
  474. insets.bottom = 0;
  475. self.tableView.contentInset = insets;
  476. }
  477. @end