123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- #import "CPDFViewController.h"
- #import <ComPDFKit/ComPDFKit.h>
- #import <compdfkit_tools/compdfkit_tools.h>
- @interface CPDFViewController () <CPDFToolsViewControllerDelegate,CPDFFormBarDelegate,CPDFBOTAViewControllerDelegate,CPDFListViewDelegate,CPDFSignatureViewControllerDelegate>
- @property(nonatomic, strong) CPDFFormBar * formBar;
- @property(nonatomic, strong) CAnnotationManage *annotationManage;
- @property(nonatomic, strong) CPDFSignatureWidgetAnnotation * signatureAnnotation;
- @end
- @implementation CPDFViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.pdfListView.toolModel = CToolModelForm;
- self.pdfListView.delegate = self;
- self.view.backgroundColor = [CPDFColorUtils CPDFViewControllerBackgroundColor];
-
- [self initFormBar];
- [self enterFormMode];
- }
- - (void)initFormBar {
-
- self.annotationManage = [[CAnnotationManage alloc] initWithPDFView:self.pdfListView];
- self.formBar = [[CPDFFormBar alloc] initAnnotationManage:self.annotationManage];
-
- CGFloat height = 44.0;
- if (@available(iOS 11.0, *))
- height += self.view.safeAreaInsets.bottom;
- self.formBar.frame = CGRectMake(0, self.view.frame.size.height - height, self.view.frame.size.width, height);
- self.formBar.delegate = self;
- self.formBar.parentVC = self;
- #warning need to set parentVC
- [self.view addSubview:self.formBar];
- }
- - (void)initWitNavigationTitle {
-
- CNavigationBarTitleButton * navTitleButton = [[CNavigationBarTitleButton alloc] init];
- self.titleButton = navTitleButton;
- self.navigationTitle = NSLocalizedString(@"Form", nil);
- [navTitleButton setImage:[UIImage imageNamed:@"syasarrow"] forState:UIControlStateNormal];
- [navTitleButton addTarget:self action:@selector(titleButtonClickd:) forControlEvents:UIControlEventTouchUpInside];
- [navTitleButton setTitle:self.navigationTitle forState:UIControlStateNormal];
- [navTitleButton setTitleColor:[CPDFColorUtils CAnyReverseBackgooundColor] forState:UIControlStateNormal];
- self.titleButton.frame = CGRectMake(0, 0, 50, 30);
- self.navigationItem.titleView = self.titleButton;
- }
- - (void)viewWillLayoutSubviews {
- [super viewWillLayoutSubviews];
-
- if([self.popMenu superview]) {
- if (@available(iOS 11.0, *)) {
- [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 250, CGRectGetMaxY(self.navigationController.navigationBar.frame), 250, 200)];
- } else {
-
- [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - 250, CGRectGetMaxY(self.navigationController.navigationBar.frame), 250, 200)];
- }
- }
-
- CGFloat height = 44.0;
-
- if (@available(iOS 11.0, *))
- height += self.view.safeAreaInsets.bottom;
- if(CToolModelForm == self.pdfListView.toolModel) {
- if (@available(iOS 11.0, *)) {
- self.formBar.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.frame.size.height - height, self.view.frame.size.width- self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, height);
- } else {
- self.formBar.frame = CGRectMake(0, self.view.frame.size.height - height, self.view.frame.size.width, height);
- }
- } else {
- self.formBar.frame = CGRectMake(0, self.view.bounds.size.height, self.view.frame.size.width, height);
- }
-
- CGFloat tPosY = 0;
- CGFloat tBottomY = 0;
- if(CToolModelForm == self.pdfListView.toolModel) {
- if (!self.navigationController.navigationBarHidden) {
- [UIView animateWithDuration:0.3 animations:^{
- CGRect frame = self.formBar.frame;
- frame.origin.y = self.view.bounds.size.height-frame.size.height;
- self.formBar.frame = frame;
- }];
- CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
- tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
-
- tBottomY = self.formBar.frame.size.height;
- } else {
- [UIView animateWithDuration:0.3 animations:^{
- CGRect frame = self.formBar.frame;
- frame.origin.y = self.view.bounds.size.height;
- self.formBar.frame = frame;
- }];
- }
- } else {
- tPosY = 0;
- if (!self.navigationController.navigationBarHidden) {
- CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
- tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
- }
- }
-
- if (@available(iOS 11.0, *)) {
- self.pdfListView.frame = CGRectMake(self.view.safeAreaInsets.left, tPosY, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - tBottomY - tPosY);
- } else {
- self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height - tBottomY - tPosY);
- }
- }
- #pragma mark - Private
- - (void)enterFormMode {
- self.pdfListView.toolModel = CToolModelForm;
- self.navigationTitle = NSLocalizedString(@"Form", nil);
- [self.titleButton setTitle:self.navigationTitle forState:UIControlStateNormal];
-
- CGFloat tPosY = 0;
- CGFloat tBottomY = 0;
- CGRect frame = self.formBar.frame;
- frame.origin.y = self.view.bounds.size.height-frame.size.height;
- self.formBar.frame = frame;
-
- CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
- tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
- tBottomY = self.formBar.frame.size.height;
-
- if (@available(iOS 11.0, *)) {
- self.pdfListView.frame = CGRectMake(self.view.safeAreaInsets.left, tPosY, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - tBottomY - tPosY);
- } else {
- self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height - tBottomY - tPosY);
- }
- [self.formBar updateStatus];
- }
- - (void)selectDocumentRefresh {
- [super selectDocumentRefresh];
- [self.formBar initUndoRedo];
- }
- - (void)enterViewerMode {
- self.pdfListView.toolModel = CToolModelViewer;
- self.navigationTitle = NSLocalizedString(@"Viewer", nil);
- [self.titleButton setTitle:self.navigationTitle forState:UIControlStateNormal];
-
- CGRect frame = self.formBar.frame;
- frame.origin.y = self.view.bounds.size.height;
- self.formBar.frame = frame;
-
- CGFloat tPosY = 0;
- CGFloat tBottomY = 0;
-
- if (@available(iOS 11.0, *)) {
- self.pdfListView.frame = CGRectMake(self.view.safeAreaInsets.left, tPosY, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - tBottomY - tPosY);
- } else {
- self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height - tBottomY - tPosY);
- }
- }
- - (void) titleButtonClickd:(UIButton *) button {
- CPDFToolsViewController * toolsVc = [[CPDFToolsViewController alloc] initCustomizeWithToolArrays:@[@(CToolModelViewer),@(CToolModelForm)]];
- toolsVc.delegate = self;
- AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
- presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:toolsVc presentingViewController:self];
- toolsVc.transitioningDelegate = presentationController;
- [self presentViewController:toolsVc animated:YES completion:nil];
- }
- - (void)navigationRightItemBota {
- CPDFBOTAViewController *botaViewController = [[CPDFBOTAViewController alloc] initCustomizeWithPDFView:self.pdfListView navArrays:@[@(CPDFBOTATypeStateOutline),@(CPDFBOTATypeStateBookmark),@(CPDFBOTATypeStateAnnotation)]];
- botaViewController.delegate = self;
-
- AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
-
- presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:botaViewController presentingViewController:self];
- botaViewController.transitioningDelegate = presentationController;
-
- [self presentViewController:botaViewController animated:YES completion:nil];
- }
- #pragma mark - CPDFListViewDelegate
- - (void)PDFListViewPerformTouchEnded:(CPDFListView *)pdfView {
- CGFloat tPosY = 0;
- CGFloat tBottomY = 0;
- if(CToolModelForm == self.pdfListView.toolModel) {
- if (self.navigationController.navigationBarHidden) {
- [self.navigationController setNavigationBarHidden:NO animated:YES];
- [UIView animateWithDuration:0.3 animations:^{
- CGRect frame = self.formBar.frame;
- frame.origin.y = self.view.bounds.size.height-frame.size.height;
- self.formBar.frame = frame;
- self.pdfListView.pageSliderView.alpha = 1.0;
- }];
- CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
- tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
-
- tBottomY = self.formBar.frame.size.height;
- } else {
- [self.navigationController setNavigationBarHidden:YES animated:YES];
- [UIView animateWithDuration:0.3 animations:^{
- CGRect frame = self.formBar.frame;
- frame.origin.y = self.view.bounds.size.height;
- self.formBar.frame = frame;
- self.pdfListView.pageSliderView.alpha = 0.0;
- }];
- }
- } else {
- CGFloat tPosY = 0;
- if (self.navigationController.navigationBarHidden) {
- [self.navigationController setNavigationBarHidden:NO animated:YES];
- [UIView animateWithDuration:0.3 animations:^{
- self.pdfListView.pageSliderView.alpha = 1.0;
- }];
- CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
- tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
- } else {
- [self.navigationController setNavigationBarHidden:YES animated:YES];
- [UIView animateWithDuration:0.3 animations:^{
- self.pdfListView.pageSliderView.alpha = 0.0;
- }];
- }
- }
-
- if (@available(iOS 11.0, *)) {
- self.pdfListView.frame = CGRectMake(self.view.safeAreaInsets.left, tPosY, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - tBottomY - tPosY);
- } else {
- self.pdfListView.frame = CGRectMake(0, tPosY, self.view.frame.size.width, self.view.frame.size.height - tBottomY - tPosY);
- }
- }
- - (void)PDFListViewChangedAnnotationType:(CPDFListView *)pdfListView forAnnotationMode:(CPDFViewAnnotationMode)annotationMode {
- [self.formBar reloadData];
- }
- - (void)PDFListViewPerformUrl:(CPDFListView *)pdfView withContent:(NSString *)content {
- NSURL * url = [NSURL URLWithString:content];
- [[UIApplication sharedApplication] openURL:url];
- }
- - (void)PDFListViewPerformSignatureWidget:(CPDFListView *)pdfView forAnnotation:(CPDFSignatureWidgetAnnotation *)annotation {
- if(CToolModelViewer == self.pdfListView.toolModel) {
- self.signatureAnnotation = annotation;
- AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
- CPDFSignatureViewController *signatureVC = [[CPDFSignatureViewController alloc] initWithStyle:nil];
- presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:signatureVC presentingViewController:self];
- signatureVC.delegate = self;
- signatureVC.transitioningDelegate = presentationController;
- [self presentViewController:signatureVC animated:YES completion:nil];
- }
- }
- - (void)PDFListViewEditWidget:(CPDFListView *)pdfListView forAnnotation:(CPDFAnnotation *)annotation {
- [self.formBar buttonItemClicked_openOption:annotation];
- }
- - (void)PDFListViewEditProperties:(CPDFListView *)pdfListView forAnnotation:(CPDFAnnotation *)annotation {
- [self.formBar buttonItemClicked_open:annotation];
- }
- #pragma mark - CPDFBOTAViewControllerDelegate
- - (void)botaViewControllerDismiss:(CPDFBOTAViewController *)botaViewController {
- [self.navigationController dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma mark - CPDFAnnotationBarDelegate
- - (void)formBarClick:(CPDFFormBar *)pdfFormBar forSelected:(BOOL)isSelected forButton:(UIButton *)button {
- NSLog(@"form bar Clicked!");
- }
- #pragma mark - CPDFNoteOpenViewControllerDelegate
- #pragma mark - CPDFToolsViewControllerDelegate
- - (void)CPDFToolsViewControllerDismiss:(CPDFToolsViewController *) viewController selectItemAtIndex:(CToolModel)selectIndex {
- if(CToolModelViewer == selectIndex) {
-
- [self enterViewerMode];
- }else{
-
- [self enterFormMode];
- }
- }
- #pragma mark - CPDFSignatureViewControllerDelegate
- - (void)signatureViewControllerDismiss:(CPDFSignatureViewController *)signatureViewController {
- self.signatureAnnotation = nil;
- }
- - (void)signatureViewController:(CPDFSignatureViewController *)signatureViewController image:(UIImage *)image {
- if(self.signatureAnnotation) {
- [self.signatureAnnotation signWithImage:image];
- [self.pdfListView setNeedsDisplayForPage:self.signatureAnnotation.page];
- self.signatureAnnotation = nil;
- }
- }
- @end
|