| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585 |
- //
- // DocumentViewController.m
- // AntsContract
- //
- // Created by Ray on 12/16/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "PageViewController.h"
- #import "config.h"
- #import "const.h"
- #import "SignatureListViewController.h"
- #import "SignatureViewController.h"
- #import "PDFUtils.h"
- #import "ImageUtils.h"
- #import "CheckSelectorViewController.h"
- //#import "TouchImageView.h"
- @interface PageViewController ()
- @end
- @implementation PageViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // self.pageIndex=1;
-
- // self.pdfPageView.pageIndex=self.pageIndex;
- self.pdfPageView.pageRef= self.pageRef;
-
- [self initControl];
-
- // UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc]
- // initWithTarget:self
- // action:@selector(handlePinch:)];
- //
- // [self.view addGestureRecognizer:pinchGestureRecognizer];
-
- // Do any additional setup after loading the view.
- }
- -(void) dealloc
- {
- // CFBridgingRelease(self.pageRef);
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- //- (void) handlePinch:(UIPinchGestureRecognizer*) recognizer
- //{
- //// recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
- //// recognizer.scale = 1;
- //
- // CGSize contentsize =self.pdfScrollView.contentSize;
- //
- // self.pdfScrollView.contentSize = CGSizeMake(contentsize.width*recognizer.scale, contentsize.height*recognizer.scale);
- //}
- -(void) initControl
- {
- int count = [self.controlTemplate[@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * control =self.controlTemplate [[NSString stringWithFormat:@"control_%d",i] ];
- if([control[@"type"] isEqualToString:@"TextView"])
- {
- [self addTextView:control destView:self.editControlView index:i];
- }
- else if([control[@"type"] isEqualToString:@"Button"])
- {
- [self addButton:control destView:self.editControlView index:i];
-
- }
- else if([control[@"type"] isEqualToString:@"Check"])
- {
- [self addCheck:control destView:self.editControlView index:i];
-
- }
- else if([control[@"type"] isEqualToString:@"Signature"])
- {
- [self addSignatureButton:control destView:self.editControlView index:i];
-
- }
- else if([control[@"type"] isEqualToString:@"Image"])
- {
- [self addImage:control destView:self.editControlView index:i];
-
- }
- else if([control[@"type"] isEqualToString:@"Label"])
- {
- [self addLabel:control destView:self.editControlView index:i];
-
- }
- }
-
- }
- #pragma mark add controls
- -(void) addTextView:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
- {
- UITextView* tv = [[UITextView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
- float fontsize = [template[@"size"] floatValue];
- if(fontsize==0)
- fontsize=10;
- [tv setFont:[UIFont systemFontOfSize:fontsize]];
-
- tv.text =template[@"value"];
-
- tv.tag = index+ CONTROL_BASE;
-
-
-
- //UIColorFromARGB(0x4066ccff);
-
- tv.backgroundColor = UIColorFromRGB(TV_BG);//[UIColor lightGrayColor];
- // tv.place
- // [btn setTitle:template[@"title"] forState:UIControlStateNormal];
- // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
-
-
- tv.delegate = self;
- // [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
- if(DEBUG_PDFSIG)
- {
-
- // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
- }
- [destView addSubview:tv];
- }
- -(void) addLabel:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
- {
- UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
- float fontsize = [template[@"size"] floatValue];
- if(fontsize==0)
- fontsize=10;
- [label setFont:[UIFont systemFontOfSize:fontsize]];
-
- label.text =template[@"value"];
-
- label.tag = index+ CONTROL_BASE;
-
-
-
- //UIColorFromARGB(0x4066ccff);
-
- // tv.backgroundColor = UIColorFromRGB(TV_BG);//[UIColor lightGrayColor];
- // tv.place
- // [btn setTitle:template[@"title"] forState:UIControlStateNormal];
- // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
-
-
- // tv.delegate = self;
- // [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
- if(DEBUG_PDFSIG)
- {
-
- [label setBackgroundColor:[UIColor grayColor]];
-
- }
- [destView addSubview:label];
- }
- -(void) addButton:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
- {
- UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
- [btn setTitle:template[@"title"] forState:UIControlStateNormal];
-
- btn.tag = index+ CONTROL_BASE;
- // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
- btn.backgroundColor = UIColorFromRGB(BT_BG);
- [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
- if(DEBUG_PDFSIG)
- {
- // btn.backgroundColor = [UIColor lightGrayColor];
-
- // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
- }
- [destView addSubview:btn];
- }
- -(UIView*) createMarker:(int)size x:(int)x y:(int)y
- {
- UIView* v=[[UIView alloc] initWithFrame:CGRectMake(x, y, size, size)];
- return v;
-
- }
- -(void) addCheck:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
- {
- UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
-
- // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
- btn.tag = index+ CONTROL_BASE;
- [btn addTarget:self action:@selector(CheckButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
- UIColor* marker_bg=UIColorFromRGB(CK_BG);//[UIColor clearColor];
- if(DEBUG_PDFSIG)
- {
- btn.backgroundColor = [UIColor lightGrayColor];
- [btn setTitle:template[@"title"] forState:UIControlStateNormal];
- // marker_bg = [UIColor redColor];
-
- // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
- }
- [destView addSubview:btn];
- NSArray* cadedate = template[@"cadedate"];
-
- NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%d",index] ][@"value"];
- // if(checkedData.count>0)
- // marker_bg = [UIColor clearColor];
- // else
- marker_bg=UIColorFromRGB(CK_BG);
-
- for(int i=0;i<cadedate.count;i++)
- {
- NSArray* item = cadedate[i];
-
- UIView* marker=[self createMarker:[template[@"marker_size"] intValue] x:[item[1][0] intValue] y:[item[1][1] intValue]];
-
- marker.backgroundColor = marker_bg;
- marker.tag = CHECK_BASE+index*1000+i;
-
-
- if([checkedData containsObject:[NSNumber numberWithLong:i]])
- {
-
- marker.backgroundColor= UIColorFromRGB(CK_MK);
-
- }
- else
- {
- marker.backgroundColor= marker_bg;
- }
-
- [destView addSubview:marker];
-
- }
-
- }
- -(void) addSignatureButton:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
- {
- TouchImageView* btn = [[TouchImageView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
-
- btn.contentMode = UIViewContentModeScaleAspectFit;
- btn.delegate = self;
- btn.layer.borderColor = [UIColor clearColor].CGColor;
- btn.layer.borderWidth = 0;
- btn.tag = index+ CONTROL_BASE;
-
- NSString* file =template[@"value"];
-
- NSData* img_data=[ImageUtils load_img:file];
-
- if(img_data!=nil)
- {
-
- UIImage* image=[UIImage imageWithData:img_data];
- btn.image = image;
-
- }
-
- btn.backgroundColor = UIColorFromRGB(SIG_BG);
- if(DEBUG_PDFSIG)
- {
-
-
- // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
- }
- [destView addSubview:btn];
- }
- -(void) addImage:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
- {
- UIImageView* btn = [[UIImageView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
-
- btn.contentMode = UIViewContentModeScaleAspectFit;
-
- btn.layer.borderColor = [UIColor clearColor].CGColor;
- btn.layer.borderWidth = 0;
- btn.tag = index+ CONTROL_BASE;
-
- NSString* file =template[@"value"];
-
- NSData* img_data=[ImageUtils load_img:file];
-
- if(img_data!=nil)
- {
-
- UIImage* image=[UIImage imageWithData:img_data];
- btn.image = image;
-
- }
-
-
- btn.backgroundColor = UIColorFromRGB(SIG_BG);
-
- if(DEBUG_PDFSIG)
- {
-
-
- // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
- }
- [destView addSubview:btn];
- }
- #pragma mark UIScrollView delegate
- - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
-
-
- UIView *subView = [scrollView viewWithTag:1024];
- return subView;
-
- }
- //- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
- //
- //
- //
- //}
- #pragma mark Button Click
- - (void)ControlButtonClicked:(UIButton *)sender {
- // DebugLog(@"cart sort button clicked");
-
- NSLog(@"button clicked;");
- // [self.view addSubview:self.sortItemController.view];
- }
- - (void)CheckButtonClicked:(UIButton *)sender {
- // DebugLog(@"cart sort button clicked");
-
- NSLog(@"check clicked;");
-
- long index = sender.tag - CONTROL_BASE;
-
- bool single_select = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"single_select"] boolValue];
- bool show_detail = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"show_detail"] boolValue];
- NSArray* rowData = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"cadedate"];
- NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"];
- CheckSelectorViewController *checkVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"CheckSelectorViewController"];
-
- checkVC.blk_OK = ^(NSArray* checkedData){
- for(int i=0;i<rowData.count;i++)
- {
- long tag=CHECK_BASE+index*1000+i;
- // UIView* v= sender;
- if([checkedData containsObject:[NSNumber numberWithLong:i]])
- {
- // [checkedData removeObject:[NSNumber numberWithLong:indexPath.row]];
-
- [sender.superview viewWithTag:tag].backgroundColor= [UIColor blackColor];
-
- }
- else
- {
- // [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
- [sender.superview viewWithTag:tag].backgroundColor= [UIColor clearColor];
- }
- self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"]=checkedData;
-
- }
- };
- checkVC.rowData = rowData;
- checkVC.checkedData = [checkedData mutableCopy];
- checkVC.single_select = single_select;
- checkVC.show_detail = show_detail;
-
- checkVC.title=@"abcdefg";
- checkVC.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
- [self presentViewController:checkVC animated:YES completion:nil];
-
- }
- #pragma mark TextViewDelegate
- - (void)textViewDidEndEditing:(UITextView *)textView
- {
-
- long index = textView.tag - CONTROL_BASE;
-
- NSString* text =textView.text;
- if(text==nil)
- text=@"";
- self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = text;
-
- // int count = [self.controlTemplate[@"count"] intValue];
- // for(int i=0;i<count;i++)
- // {
- // NSMutableDictionary * control =;
- //[self update_newprice];
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- #pragma mark signature clicked
- //touchimageview Delegate
- - (void)TouchImageViewOnTouche:(TouchImageView *)touchImageView
- {
-
- NSLog(@"signature button clicked;");
-
-
- {
-
- // CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:trigger];
- //
- //
- // CGRect rect1=[self.view convertRect:cellrect_screen fromView:[[[UIApplication sharedApplication] delegate] window]];
- //
- // DebugLog(@"convert1 %@",NSStringFromCGRect(rect1));
- SignatureListViewController *signatureVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureListViewController"];
- signatureVC.title=@"Signatures";
- signatureVC.signatureData = self.signatureData;
-
- // signatureVC.imageView = touchImageView;
-
- signatureVC.blk_Select =^(NSString* file)
- {
-
-
-
- // NSString* file_name=[file lastPathComponent];
-
- NSData* img_data=[ImageUtils load_img:file];
-
- if(img_data!=nil)
- {
-
- UIImage* image=[UIImage imageWithData:img_data];
- touchImageView.image = image;
-
- long index = touchImageView.tag - CONTROL_BASE;
- self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
-
- }
- };
- signatureVC.blk_Add = ^()
- {
-
- __block UIImage* signimg=nil;
- SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
-
- vc.onReturnImg = ^(UIImage* img)
- {
-
-
- signimg = img;
-
- if(signimg!=nil)
- {
- NSString* file=[PDFUtils addSignature:signimg to:self.signatureData];
- long index = touchImageView.tag - CONTROL_BASE;
- self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
- touchImageView.image = signimg;
- }
-
-
- };
- // orderinfoVC.url_type = URL_REMOTE;
- // orderinfoVC.request_url=URL_CARTDELIVERY;
- //
- // orderinfoVC.params = params;
- //
- // orderinfoVC.delegate=self;
- //
- // if(checked.count==count)
- // {
- // orderinfoVC.have_tail = true
- // }
-
- [self.navigationController pushViewController:vc animated:true];
-
-
-
- };
-
- UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:signatureVC];
- navi.modalPresentationStyle=UIModalPresentationPopover;
-
- UIPopoverPresentationController* popPc = navi.popoverPresentationController;
- popPc.permittedArrowDirections = UIPopoverArrowDirectionAny;
- popPc.sourceView = touchImageView;
- popPc.delegate = nil;
-
-
-
- [self presentViewController:navi animated:true completion:nil];
-
- //// menu.selector = self.selector;
- ////
- //// menu.selectordelegate = self;
- //
- // // 1.创建一个UIPopover
- // UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]];
- //
- //
- //
- // UIPopoverPresentationController
- // // 2.设置尺寸
- // // popover.popoverContentSize = CGSizeMake(320, 44 * 5);
- //
- // // 3.从哪里显示出来 --> 指向item
- //
- // [popover presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:0 animated:YES];
- // // [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
- //
- //// self.popover = popover;
- // popover pop
- //
- // [self performSegueWithIdentifier:@"selector_popover" sender:self];
-
- }
- // __block int tag = touchImageView.tag;
- // UIViewController* vc=[RAUtils getViewController :touchImageView];
- //
- // if(self.editable==true)
- // {
- //
- //
- // ImageUploadViewController * uploadvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageUploadViewController"];
- //
- // // UIImage* img =[self.buttonImg backgroundImageForState:UIControlStateNormal];;
- //
- // if(self.img_validate)
- // uploadvc.img= touchImageView.image;
- //
- // uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
- // {
- //
- // self.imgs[tag] = url_up;
- //
- // NSString* newurl=[RAUtils arr2string:self.imgs separator:@"," trim:false];
- //
- // touchImageView.image=img;
- //
- // if(self.imgChanged)
- // self.imgChanged(url_down,newurl,tag,url_up);
- //
- // };
- //
- // [vc.navigationController pushViewController:uploadvc animated:false];
- // }
- // else
- // {
- // if(touchImageView.image==nil)
- // return ;
- // ImageViewController * imagevc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageViewController"];
- //
- //
- // UIImage* img=touchImageView.image;
- //
- // if(self.img_validate)
- // imagevc.image = img;//.imageView.image = [self.buttonImg backgroundImageForState:UIControlStateNormal];
- //
- // // uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
- // // {
- // //
- // // [self.buttonImg setBackgroundImage:img forState:UIControlStateNormal];
- // //
- // // if(self.imgChanged)
- // // self.imgChanged(url_down,url_up);
- // //
- // // };
- //
- // [vc.navigationController pushViewController:imagevc animated:false];
- // }
- // // bundleVC.content_data = self.bundle_item;
- //
-
- }
- @end
|