CPDFBOTAViewController.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // CPDFBOTAViewController.m
  3. // compdfkit-tools
  4. //
  5. // Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CPDFBOTAViewController.h"
  13. #import "CPDFThumbnailViewController.h"
  14. #import "CPDFOutlineViewController.h"
  15. #import "CPDFBookmarkViewController.h"
  16. #import "CPDFColorUtils.h"
  17. #import <ComPDFKit/ComPDFKit.h>
  18. @interface CPDFBOTAViewController () <CPDFOutlineViewControllerDelegate, CPDFBookmarkViewControllerDelegate>
  19. @property (nonatomic, assign) NSInteger pageIndex;
  20. @property (nonatomic, strong) UISegmentedControl *segmentedControl;
  21. @property (nonatomic, strong) UIViewController *currentViewController;
  22. @property (nonatomic, strong) CPDFOutlineViewController *outlineViewController;
  23. @property (nonatomic, strong) CPDFBookmarkViewController *bookmarkViewController;
  24. @end
  25. @implementation CPDFBOTAViewController
  26. #pragma mark - Initializers
  27. - (instancetype)initWithPDFView:(CPDFView *)pdfView {
  28. if (self = [super init]) {
  29. _pdfView = pdfView;
  30. }
  31. return self;
  32. }
  33. #pragma mark - Accessors
  34. - (CPDFBookmarkViewController *)bookmarkViewController {
  35. if (!_bookmarkViewController) {
  36. }
  37. return _bookmarkViewController;
  38. }
  39. #pragma mark - UIViewController Methods
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. // Do any additional setup after loading the view.
  43. self.view.backgroundColor = [CPDFColorUtils CPDFViewControllerBackgroundColor];
  44. self.outlineViewController = [[CPDFOutlineViewController alloc] initWithPDFView:self.pdfView];
  45. self.outlineViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
  46. self.outlineViewController.delegate = self;
  47. [self addChildViewController:self.outlineViewController];
  48. _bookmarkViewController = [[CPDFBookmarkViewController alloc] initWithPDFView:self.pdfView];
  49. _bookmarkViewController.delegate = self;
  50. _bookmarkViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
  51. [self addChildViewController:_bookmarkViewController];
  52. NSArray *segmmentArray = [NSArray arrayWithObjects:NSLocalizedString(@"Outline", nil), NSLocalizedString(@"Bookmark", nil), nil];
  53. _segmentedControl = [[UISegmentedControl alloc] initWithItems:segmmentArray];
  54. _segmentedControl.selectedSegmentIndex = 0;
  55. _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  56. [_segmentedControl addTarget:self action:@selector(segmentedControlValueChanged_BOTA:) forControlEvents:UIControlEventValueChanged];
  57. self.navigationItem.titleView = self.segmentedControl;
  58. self.currentViewController = self.outlineViewController;
  59. [self.view addSubview:self.outlineViewController.view];
  60. }
  61. - (void)viewWillLayoutSubviews {
  62. _segmentedControl.frame = CGRectMake(self.view.frame.size.width / 4, 0 , self.view.frame.size.width / 2, 30);
  63. if (@available(iOS 11.0, *)) {
  64. self.outlineViewController.view.frame = CGRectMake(0, self.view.safeAreaInsets.top, self.view.bounds.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.bounds.size.height - self.view.safeAreaInsets.top - self.view.safeAreaInsets.bottom);
  65. _bookmarkViewController.view.frame = CGRectMake(0, self.view.safeAreaInsets.top, self.view.bounds.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.bounds.size.height - self.view.safeAreaInsets.top - self.view.safeAreaInsets.bottom);
  66. } else {
  67. self.outlineViewController.view.frame = CGRectMake(0, 64, self.view.bounds.size.width - 64 - 30, self.view.bounds.size.height - 64 - 30);
  68. _bookmarkViewController.view.frame = CGRectMake(0, 64, self.view.bounds.size.width - 64 - 30, self.view.bounds.size.height - 64 - 30);
  69. }
  70. }
  71. #pragma mark - Action
  72. - (void)segmentedControlValueChanged_BOTA:(id)sender {
  73. [self.currentViewController.view removeFromSuperview];
  74. if (self.segmentedControl.selectedSegmentIndex == 0) {
  75. self.currentViewController = self.outlineViewController;
  76. [self.view addSubview:self.outlineViewController.view];
  77. } else if (self.segmentedControl.selectedSegmentIndex == 1) {
  78. self.currentViewController = self.bookmarkViewController;
  79. [self.view addSubview:self.bookmarkViewController.view];
  80. }
  81. }
  82. #pragma mark - CPDFOutlineViewControllerDelegate
  83. - (void)outlineViewController:(CPDFOutlineViewController *)outlineViewController pageIndex:(NSInteger)pageIndex {
  84. [self.pdfView goToPageIndex:pageIndex animated:NO];
  85. if([self.delegate respondsToSelector:@selector(botaViewControllerDismiss:)]) {
  86. [self.delegate botaViewControllerDismiss:self];
  87. }
  88. }
  89. #pragma mark - CPDFBookmarkViewControllerDelegate
  90. - (void)boomarkViewController:(CPDFBookmarkViewController *)bookmarkViewController pageIndex:(NSInteger)pageIndex {
  91. [self.pdfView goToPageIndex:pageIndex animated:NO];
  92. if([self.delegate respondsToSelector:@selector(botaViewControllerDismiss:)]) {
  93. [self.delegate botaViewControllerDismiss:self];
  94. }
  95. }
  96. @end