PDFBOTAViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // PDFBOTAViewController.m
  3. // PDFReader
  4. //
  5. // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // The PDF Reader Sample applications are licensed with a modified BSD license.
  8. // Please see License for details. This notice may not be removed from this file.
  9. //
  10. #import "PDFBOTAViewController.h"
  11. #import "PDFAnnotationListViewController.h"
  12. #import "PDFOutlineViewController.h"
  13. #import "PDFBookmarkViewController.h"
  14. #import "PDFThumbnailViewController.h"
  15. @interface PDFBOTAViewController () <UIPopoverPresentationControllerDelegate>
  16. @property (nonatomic,assign) IBOutlet UISegmentedControl *segmentedControl;
  17. @property (nonatomic,retain) UIViewController *currentViewController;
  18. @property (nonatomic,retain) PDFAnnotationListViewController *annotationViewController;
  19. @property (nonatomic,retain) PDFOutlineViewController *outlineViewController;
  20. @property (nonatomic,retain) PDFBookmarkViewController *bookmarkViewController;
  21. @property (nonatomic,retain) PDFThumbnailViewController *thumbnailViewController;
  22. @end
  23. @implementation PDFBOTAViewController
  24. #pragma mark - Init Methods
  25. - (void)dealloc {
  26. [_annotationViewController release];
  27. [_outlineViewController release];
  28. [_bookmarkViewController release];
  29. [_thumbnailViewController release];
  30. [_currentViewController release];
  31. [super dealloc];
  32. }
  33. #pragma mark - Getter Methods
  34. - (PDFAnnotationListViewController *)annotationViewController {
  35. if (!_annotationViewController) {
  36. _annotationViewController = [[PDFAnnotationListViewController alloc] init];
  37. _annotationViewController.pdfViewController = self.pdfViewController;
  38. [self addChildViewController:_annotationViewController];
  39. }
  40. return _annotationViewController;
  41. }
  42. - (PDFOutlineViewController *)outlineViewController {
  43. if (!_outlineViewController) {
  44. _outlineViewController = [[PDFOutlineViewController alloc] init];
  45. _outlineViewController.pdfViewController = self.pdfViewController;
  46. [self addChildViewController:_outlineViewController];
  47. }
  48. return _outlineViewController;
  49. }
  50. - (PDFBookmarkViewController *)bookmarkViewController {
  51. if (!_bookmarkViewController) {
  52. _bookmarkViewController = [[PDFBookmarkViewController alloc] init];
  53. _bookmarkViewController.pdfViewController = self.pdfViewController;
  54. [self addChildViewController:_bookmarkViewController];
  55. }
  56. return _bookmarkViewController;
  57. }
  58. - (PDFThumbnailViewController *)thumbnailViewController {
  59. if (!_thumbnailViewController) {
  60. _thumbnailViewController = [[PDFThumbnailViewController alloc] init];
  61. _thumbnailViewController.pdfViewController = self.pdfViewController;
  62. [self addChildViewController:_thumbnailViewController];
  63. }
  64. return _thumbnailViewController;
  65. }
  66. #pragma mark - UIViewController Methods
  67. - (void)viewDidLoad {
  68. [super viewDidLoad];
  69. // Do any additional setup after loading the view from its nib.
  70. self.navigationItem.titleView = self.segmentedControl;
  71. [self segmentedControlValueChanged_BOTA:nil];
  72. }
  73. - (void)viewWillAppear:(BOOL)animated {
  74. [super viewWillAppear:animated];
  75. self.navigationController.navigationBar.translucent = NO;
  76. }
  77. #pragma mark - Button Actions
  78. - (IBAction)segmentedControlValueChanged_BOTA:(id)sender {
  79. [self.currentViewController.view removeFromSuperview];
  80. if (self.segmentedControl.selectedSegmentIndex == 0) {
  81. self.currentViewController = self.annotationViewController;
  82. [self.view addSubview:self.annotationViewController.view];
  83. self.annotationViewController.view.frame = self.view.bounds;
  84. self.annotationViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  85. } else if (self.segmentedControl.selectedSegmentIndex == 1) {
  86. self.currentViewController = self.outlineViewController;
  87. [self.view addSubview:self.outlineViewController.view];
  88. self.outlineViewController.view.frame = self.view.bounds;
  89. self.outlineViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  90. } else if (self.segmentedControl.selectedSegmentIndex == 2) {
  91. self.currentViewController = self.bookmarkViewController;
  92. [self.view addSubview:self.bookmarkViewController.view];
  93. self.bookmarkViewController.view.frame = self.view.bounds;
  94. self.bookmarkViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  95. } else if (self.segmentedControl.selectedSegmentIndex == 3) {
  96. self.currentViewController = self.thumbnailViewController;
  97. [self.view addSubview:self.thumbnailViewController.view];
  98. self.thumbnailViewController.view.frame = self.view.bounds;
  99. self.thumbnailViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  100. }
  101. }
  102. #pragma mark - Public Methods
  103. - (void)showViewController:(UIViewController *)viewController inBarButtonItem:(UIBarButtonItem *)barButtonItem {
  104. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self];
  105. nav.modalPresentationStyle = UIModalPresentationPopover;
  106. UIPopoverPresentationController *popVC = nav.popoverPresentationController;
  107. popVC.delegate = self;
  108. popVC.barButtonItem = barButtonItem;
  109. popVC.permittedArrowDirections = UIPopoverArrowDirectionUp;
  110. [viewController presentViewController:nav animated:YES completion:nil];
  111. [nav release];
  112. }
  113. #pragma mark - UIPopoverPresentationControllerDelegate
  114. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
  115. return UIModalPresentationNone;
  116. }
  117. @end