CPDFPDFInsertViewController.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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, strong) UIScrollView *scrcollView;
  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.scrcollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-50)];
  81. self.scrcollView.scrollEnabled = YES;
  82. self.scrcollView.contentSize = CGSizeMake(self.view.frame.size.width, 800);
  83. self.scrcollView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  84. self.scrcollView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
  85. [self.view addSubview:self.scrcollView];
  86. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-50) style:UITableViewStylePlain];
  87. self.tableView.delegate = self;
  88. self.tableView.dataSource = self;
  89. self.tableView.rowHeight = 60.0;
  90. self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  91. self.tableView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
  92. [self.scrcollView addSubview:self.tableView];
  93. self.isSelect = NO;
  94. self.view.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  95. self.pageModel = [[CBlankPageModel alloc] init];
  96. self.pageModel.pageIndex = 0;
  97. self.pageModel.rotation = 0;
  98. NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
  99. for (int i = 0; i < self.document.pageCount; i++) {
  100. [indexSet addIndex:i];
  101. }
  102. self.pageModel.indexSet = indexSet;
  103. self.pageLoactionBtns = [NSMutableArray array];
  104. self.pageRangeBtns = [NSMutableArray array];
  105. [[NSNotificationCenter defaultCenter] addObserver:self
  106. selector:@selector(keyboardwillChangeFrame:)
  107. name:UIKeyboardWillChangeFrameNotification
  108. object:nil];
  109. [[NSNotificationCenter defaultCenter] addObserver:self
  110. selector:@selector(keyboardWillHide:)
  111. name:UIKeyboardWillHideNotification
  112. object:nil];
  113. }
  114. - (void)viewWillLayoutSubviews {
  115. [super viewWillLayoutSubviews];
  116. self.headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, 50);
  117. self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 200)/2, 0, 200, 50);
  118. self.scrcollView.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-50);
  119. if (@available(iOS 11.0, *)) {
  120. self.saveButton.frame = CGRectMake(self.view.frame.size.width - 60 - self.view.safeAreaInsets.right, 5, 50, 40);
  121. self.cancelBtn.frame = CGRectMake( self.view.safeAreaInsets.left+20, 5, 50, 40);
  122. } else {
  123. self.saveButton.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 40);
  124. self.cancelBtn.frame = CGRectMake(20, 5, 50, 40);
  125. }
  126. }
  127. #pragma mark - Private Methods
  128. - (void)popoverWarning {
  129. UIAlertAction *OKAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
  130. style:UIAlertActionStyleDefault
  131. handler:^(UIAlertAction *action) {
  132. }];
  133. UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Warning", nil)
  134. message:NSLocalizedString(@"Sorry,out of page scope", nil)
  135. preferredStyle:UIAlertControllerStyleAlert];
  136. [alert addAction:OKAction];
  137. [self presentViewController:alert animated:YES completion:nil];
  138. }
  139. - (NSString *)stringByTruncatingMiddleWithFont:(UIFont *)font maxLength:(CGFloat)maxLength {
  140. if ([[self.document.documentURL lastPathComponent] sizeWithAttributes:@{NSFontAttributeName: font}].width <= maxLength) {
  141. return [self.document.documentURL lastPathComponent];
  142. }
  143. NSInteger halfLength = ([self.document.documentURL lastPathComponent].length) / 4;
  144. NSString *firstHalf = [[self.document.documentURL lastPathComponent] substringToIndex:halfLength];
  145. NSString *secondHalf = [[self.document.documentURL lastPathComponent] substringFromIndex:[self.document.documentURL lastPathComponent].length - halfLength];
  146. NSString *truncatedStr = [NSString stringWithFormat:@"%@...%@", firstHalf, secondHalf];
  147. return truncatedStr;
  148. }
  149. #pragma mark - Action
  150. - (void)buttonItemClicked_save:(id)sender {
  151. [self dismissViewControllerAnimated:YES completion:^{
  152. if (self.delegate && [self.delegate respondsToSelector:@selector(pdfInsertViewControllerSave:pageModel:)]) {
  153. [self.delegate pdfInsertViewControllerSave:self pageModel:self.pageModel];
  154. }
  155. }];
  156. }
  157. - (void)buttonItemClicked_cancel:(id)sender {
  158. [self dismissViewControllerAnimated:YES completion:^{
  159. if (self.delegate && [self.delegate respondsToSelector:@selector(pdfInsertViewControllerCancel:)]) {
  160. [self.delegate pdfInsertViewControllerCancel:self];
  161. }
  162. }];
  163. }
  164. #pragma mark - UITableViewDataSource
  165. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  166. return self.dataArray.count;
  167. }
  168. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  169. CInsertBlankPageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pageCell"];
  170. if (cell == nil) {
  171. cell = [[CInsertBlankPageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"pageCell"];
  172. cell.delegate = self;
  173. }
  174. switch (indexPath.row) {
  175. case 0:
  176. {
  177. [cell setCellStyle:CInsertBlankPageCellSize label:self.dataArray[indexPath.row]];
  178. CGFloat maxLength = 200.0;
  179. UIFont *font = [UIFont systemFontOfSize:18.0];
  180. cell.sizeLabel.text = [self stringByTruncatingMiddleWithFont:font maxLength:maxLength];
  181. }
  182. break;
  183. case 1:
  184. [cell setCellStyle:CInsertBlankPageCellLocation label:self.dataArray[indexPath.row]];
  185. break;
  186. case 2:
  187. {
  188. [cell setCellStyle:CInsertBlankPageCellRangeSelect label:self.dataArray[indexPath.row]];
  189. if (![self.pageRangeBtns containsObject:cell.rangeSelectBtn]) {
  190. [self.pageRangeBtns addObject:cell.rangeSelectBtn];
  191. }
  192. self.rangePreCell = cell;
  193. cell.rangeSelectBtn.selected = !cell.rangeSelectBtn.selected;
  194. cell.rangeSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  195. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  196. }
  197. break;
  198. case 3 ... 5:
  199. {
  200. [cell setCellStyle:CInsertBlankPageCellRangeSelect label:self.dataArray[indexPath.row]];
  201. if (![self.pageRangeBtns containsObject:cell.rangeSelectBtn]) {
  202. [self.pageRangeBtns addObject:cell.rangeSelectBtn];
  203. }
  204. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  205. }
  206. break;
  207. case 6:
  208. [cell setCellStyle:CInsertBlankPageCellRangeTextFiled label:self.dataArray[indexPath.row]];
  209. break;
  210. case 7:
  211. [cell setCellStyle:CInsertBlankPageCellLocation label:self.dataArray[indexPath.row]];
  212. break;
  213. case 8:
  214. {
  215. [cell setCellStyle:CInsertBlankPageCellLocationSelect label:self.dataArray[indexPath.row]];
  216. if (![self.pageLoactionBtns containsObject:cell.locationSelectBtn]) {
  217. [self.pageLoactionBtns addObject:cell.locationSelectBtn];
  218. }
  219. if (!self.currentPageIndex) {
  220. self.locationPreCell = cell;
  221. cell.locationSelectBtn.selected = !cell.locationSelectBtn.selected;
  222. cell.locationSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  223. }
  224. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  225. }
  226. break;
  227. case 9:
  228. {
  229. [cell setCellStyle:CInsertBlankPageCellLocationSelect label:self.dataArray[indexPath.row]];
  230. if (![self.pageLoactionBtns containsObject:cell.locationSelectBtn]) {
  231. [self.pageLoactionBtns addObject:cell.locationSelectBtn];
  232. }
  233. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  234. }
  235. break;
  236. case 10:
  237. {
  238. [cell setCellStyle:CInsertBlankPageCellLocationSelect label:self.dataArray[indexPath.row]];
  239. if (![self.pageLoactionBtns containsObject:cell.locationSelectBtn]) {
  240. [self.pageLoactionBtns addObject:cell.locationSelectBtn];
  241. }
  242. if (self.currentPageIndex) {
  243. self.locationPreCell = cell;
  244. cell.locationSelectBtn.selected = !cell.locationSelectBtn.selected;
  245. cell.locationSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  246. }
  247. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  248. }
  249. break;
  250. case 11:
  251. {
  252. [cell setCellStyle:CInsertBlankPageCellLocationTextFiled label:self.dataArray[indexPath.row]];
  253. if (self.currentPageIndex) {
  254. cell.locationTextField.text = [NSString stringWithFormat:@"%lu", self.currentPageIndex];
  255. self.pageModel.pageIndex = self.currentPageIndex-1;
  256. }
  257. self.locationTextField = cell.locationTextField;
  258. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  259. }
  260. break;
  261. case 12:
  262. {
  263. [cell setCellStyle:CInsertBlankPageCellLocationSelect label:self.dataArray[indexPath.row]];
  264. if (![self.pageLoactionBtns containsObject:cell.locationSelectBtn]) {
  265. [self.pageLoactionBtns addObject:cell.locationSelectBtn];
  266. }
  267. cell.separatorInset = UIEdgeInsetsMake(0, self.view.bounds.size.width, 0, 0);
  268. }
  269. break;
  270. default:
  271. break;
  272. }
  273. return cell;
  274. }
  275. #pragma mark - CInsertBlankPageCellDelegate
  276. - (void)insertBlankPageCellRange:(CInsertBlankPageCell *)insertBlankPageCell button:(UIButton *)buttom {
  277. if (self.rangePreCell) {
  278. self.rangePreCell.rangeSelectBtn.selected = !self.rangePreCell.rangeSelectBtn.selected;
  279. self.rangePreCell.rangeSelectLabel.textColor = [UIColor grayColor];
  280. if (self.rangePreCell.rangeSelectBtn != buttom) {
  281. buttom.selected = !buttom.selected;
  282. insertBlankPageCell.rangeSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  283. self.rangePreCell = insertBlankPageCell;
  284. } else {
  285. self.rangePreCell.rangeSelectLabel.textColor = [UIColor grayColor];
  286. self.rangePreCell = nil;
  287. }
  288. } else {
  289. self.rangePreCell = insertBlankPageCell;
  290. buttom.selected = !buttom.selected;
  291. insertBlankPageCell.rangeSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  292. }
  293. NSInteger range = [self.pageRangeBtns indexOfObject:buttom];
  294. switch (range) {
  295. case 0:
  296. {
  297. NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
  298. for (int i = 0; i < self.document.pageCount; i++) {
  299. [indexSet addIndex:i];
  300. }
  301. self.pageModel.indexSet = indexSet;
  302. self.rangeTextField.userInteractionEnabled = NO;
  303. }
  304. break;
  305. case 1:
  306. {
  307. NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
  308. for (int i = 0; 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 2:
  316. {
  317. NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
  318. for (int i = 1; i < self.document.pageCount; i += 2) {
  319. [indexSet addIndex:i];
  320. }
  321. self.pageModel.indexSet = indexSet;
  322. self.rangeTextField.userInteractionEnabled = NO;
  323. }
  324. break;
  325. case 4:
  326. self.rangeTextField.userInteractionEnabled = YES;
  327. break;
  328. default:
  329. break;
  330. }
  331. }
  332. - (void)insertBlankPageCellLocation:(CInsertBlankPageCell *)insertBlankPageCell button:(UIButton *)buttom {
  333. if (self.locationPreCell) {
  334. self.locationPreCell.locationSelectBtn.selected = !self.locationPreCell.locationSelectBtn.selected;
  335. self.locationPreCell.locationSelectLabel.textColor = [UIColor grayColor];
  336. if (self.locationPreCell.locationSelectBtn != buttom) {
  337. buttom.selected = !buttom.selected;
  338. insertBlankPageCell.locationSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  339. self.locationPreCell = insertBlankPageCell;
  340. } else {
  341. self.locationPreCell.locationSelectLabel.textColor = [UIColor grayColor];
  342. self.locationPreCell = nil;
  343. }
  344. } else {
  345. self.locationPreCell = insertBlankPageCell;
  346. buttom.selected = !buttom.selected;
  347. insertBlankPageCell.locationSelectLabel.textColor = [CPDFColorUtils CPageEditToolbarFontColor];
  348. }
  349. NSInteger location = [self.pageLoactionBtns indexOfObject:buttom];
  350. switch (location) {
  351. case 0:
  352. self.pageModel.pageIndex = 0;
  353. self.locationTextField.userInteractionEnabled = NO;
  354. break;
  355. case 1:
  356. self.pageModel.pageIndex = -2;
  357. self.locationTextField.userInteractionEnabled = NO;
  358. break;
  359. case 2:
  360. self.pageModel.pageIndex = self.pageModel.pageIndex - 1;
  361. self.locationTextField.userInteractionEnabled = YES;
  362. break;
  363. case 3:
  364. self.pageModel.pageIndex = self.pageModel.pageIndex + 1;
  365. self.locationTextField.userInteractionEnabled = YES;
  366. break;
  367. default:
  368. break;
  369. }
  370. }
  371. - (void)insertBlankPageCell:(CInsertBlankPageCell *)insertBlankPageCell pageRange:(NSString *)pageRange {
  372. NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
  373. if ([pageRange containsString:@","]) {
  374. NSArray<NSString *> *pageIndexsArray = [pageRange componentsSeparatedByString:@","];
  375. for (NSString *pageIndexStr in pageIndexsArray) {
  376. if ([pageIndexStr containsString:@"-"]) {
  377. NSArray<NSString *> *pageIndexs = [pageIndexStr componentsSeparatedByString:@"-"];
  378. NSInteger start = [pageIndexs[0] integerValue];
  379. NSInteger end = [pageIndexs[1] integerValue];
  380. if (end > self.document.pageCount-1) {
  381. [self popoverWarning];
  382. } else {
  383. for (NSInteger i = start; i <= end; i++) {
  384. [indexSet addIndex:i];
  385. }
  386. }
  387. } else {
  388. if ([pageIndexStr integerValue] > self.document.pageCount-1) {
  389. [self popoverWarning];
  390. } else {
  391. [indexSet addIndex:[pageIndexStr integerValue]];
  392. }
  393. }
  394. }
  395. } else {
  396. if ([pageRange containsString:@"-"]) {
  397. NSArray<NSString *> *pageIndexs = [pageRange componentsSeparatedByString:@"-"];
  398. NSInteger start = [pageIndexs[0] integerValue];
  399. NSInteger end = [pageIndexs[1] integerValue];
  400. if (end > self.document.pageCount-1) {
  401. [self popoverWarning];
  402. } else {
  403. for (NSInteger i = start; i <= end; i++) {
  404. [indexSet addIndex:i];
  405. }
  406. }
  407. } else {
  408. if ([pageRange integerValue] > self.document.pageCount-1) {
  409. [self popoverWarning];
  410. } else {
  411. [indexSet addIndex:[pageRange integerValue]];
  412. }
  413. }
  414. }
  415. self.pageModel.indexSet = indexSet;
  416. }
  417. - (void)insertBlankPageCell:(CInsertBlankPageCell *)insertBlankPageCell pageIndex:(NSInteger)pageIndex {
  418. self.pageModel.pageIndex = pageIndex;
  419. }
  420. #pragma mark - NSNotification
  421. - (void)keyboardwillChangeFrame:(NSNotification *)notification {
  422. NSDictionary *userInfo = [notification userInfo];
  423. NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  424. CGRect frame = value.CGRectValue;
  425. CGRect rect = [self.locationTextField convertRect:self.locationTextField.frame toView:self.view];
  426. if(CGRectGetMaxY(rect) > self.view.frame.size.height - frame.size.height) {
  427. UIEdgeInsets insets = self.tableView.contentInset;
  428. insets.bottom = frame.size.height + self.locationTextField.frame.size.height;
  429. self.tableView.contentInset = insets;
  430. }
  431. }
  432. - (void)keyboardWillHide:(NSNotification *)notification {
  433. UIEdgeInsets insets = self.tableView.contentInset;
  434. insets.bottom = 0;
  435. self.tableView.contentInset = insets;
  436. }
  437. @end