123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- //
- // CPDFBOTAViewController.m
- // compdfkit-tools
- //
- // Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
- //
- // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- // This notice may not be removed from this file.
- //
- #import "CPDFBOTAViewController.h"
- #import "CPDFThumbnailViewController.h"
- #import "CPDFOutlineViewController.h"
- #import "CPDFBookmarkViewController.h"
- #import "CPDFColorUtils.h"
- #import <ComPDFKit/ComPDFKit.h>
- @interface CPDFBOTAViewController () <CPDFOutlineViewControllerDelegate, CPDFBookmarkViewControllerDelegate>
- @property (nonatomic, assign) NSInteger pageIndex;
- @property (nonatomic, strong) UISegmentedControl *segmentedControl;
- @property (nonatomic, strong) UIViewController *currentViewController;
- @property (nonatomic, strong) CPDFOutlineViewController *outlineViewController;
- @property (nonatomic, strong) CPDFBookmarkViewController *bookmarkViewController;
- @end
- @implementation CPDFBOTAViewController
- #pragma mark - Initializers
- - (instancetype)initWithPDFView:(CPDFView *)pdfView {
- if (self = [super init]) {
- _pdfView = pdfView;
-
- }
- return self;
- }
- #pragma mark - Accessors
- - (CPDFBookmarkViewController *)bookmarkViewController {
- if (!_bookmarkViewController) {
-
- }
- return _bookmarkViewController;
- }
- #pragma mark - UIViewController Methods
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.view.backgroundColor = [CPDFColorUtils CPDFViewControllerBackgroundColor];
-
- self.outlineViewController = [[CPDFOutlineViewController alloc] initWithPDFView:self.pdfView];
- self.outlineViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
- self.outlineViewController.delegate = self;
- [self addChildViewController:self.outlineViewController];
-
- _bookmarkViewController = [[CPDFBookmarkViewController alloc] initWithPDFView:self.pdfView];
- _bookmarkViewController.delegate = self;
- _bookmarkViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
- [self addChildViewController:_bookmarkViewController];
-
-
- NSArray *segmmentArray = [NSArray arrayWithObjects:NSLocalizedString(@"Outline", nil), NSLocalizedString(@"Bookmark", nil), nil];
- _segmentedControl = [[UISegmentedControl alloc] initWithItems:segmmentArray];
- _segmentedControl.selectedSegmentIndex = 0;
- _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [_segmentedControl addTarget:self action:@selector(segmentedControlValueChanged_BOTA:) forControlEvents:UIControlEventValueChanged];
- self.navigationItem.titleView = self.segmentedControl;
-
- self.currentViewController = self.outlineViewController;
- [self.view addSubview:self.outlineViewController.view];
- }
- - (void)viewWillLayoutSubviews {
- _segmentedControl.frame = CGRectMake(self.view.frame.size.width / 4, 0 , self.view.frame.size.width / 2, 30);
- if (@available(iOS 11.0, *)) {
- 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);
-
- _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);
- } else {
- self.outlineViewController.view.frame = CGRectMake(0, 64, self.view.bounds.size.width - 64 - 30, self.view.bounds.size.height - 64 - 30);
-
- _bookmarkViewController.view.frame = CGRectMake(0, 64, self.view.bounds.size.width - 64 - 30, self.view.bounds.size.height - 64 - 30);
- }
- }
- #pragma mark - Action
- - (void)segmentedControlValueChanged_BOTA:(id)sender {
- [self.currentViewController.view removeFromSuperview];
-
- if (self.segmentedControl.selectedSegmentIndex == 0) {
- self.currentViewController = self.outlineViewController;
- [self.view addSubview:self.outlineViewController.view];
- } else if (self.segmentedControl.selectedSegmentIndex == 1) {
- self.currentViewController = self.bookmarkViewController;
- [self.view addSubview:self.bookmarkViewController.view];
- }
- }
- #pragma mark - CPDFOutlineViewControllerDelegate
- - (void)outlineViewController:(CPDFOutlineViewController *)outlineViewController pageIndex:(NSInteger)pageIndex {
- [self.pdfView goToPageIndex:pageIndex animated:NO];
-
- if([self.delegate respondsToSelector:@selector(botaViewControllerDismiss:)]) {
- [self.delegate botaViewControllerDismiss:self];
- }
- }
- #pragma mark - CPDFBookmarkViewControllerDelegate
- - (void)boomarkViewController:(CPDFBookmarkViewController *)bookmarkViewController pageIndex:(NSInteger)pageIndex {
- [self.pdfView goToPageIndex:pageIndex animated:NO];
-
- if([self.delegate respondsToSelector:@selector(botaViewControllerDismiss:)]) {
- [self.delegate botaViewControllerDismiss:self];
- }
- }
- @end
|