| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558 |
- //
- // DocumentViewController.m
- // AntsContract
- //
- // Created by Ray on 12/16/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #define NUMBERS @"0123456789.\n"
- #import "PageViewController.h"
- #import "config.h"
- #import "const.h"
- #import "SignatureListViewController.h"
- #import "SignatureViewController.h"
- #import "PDFUtils.h"
- #import "ImageUtils.h"
- #import "TextUtils.h"
- #import "CheckSelectorViewController.h"
- #import "DatePickerViewController.h"
- //#import "TouchImageView.h"
- @interface PageViewController ()
- @end
- @implementation PageViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- //
- // self.pdfScrollView = [[PDFScrollView alloc]initWithFrame:CGRectMake(0, 64, 768, 960)];
- // self.pdfScrollView.backgroundColor= [UIColor redColor];
-
- //self.edgesForExtendedLayout = UIRectEdgeNone;
- // self.pageIndex=1;
-
- // self.pdfPageView.pageIndex=self.pageIndex;
- self.pdfPageView.pageRef= self.pageRef;
-
- self.pdfScrollView.contentSize = self.pdfScrollView.frame.size;
- self.keyboard_h=0;
-
- [self initControl];
-
- // UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc]
- // initWithTarget:self
- // action:@selector(handlePinch:)];
- //
- // [self.view addGestureRecognizer:pinchGestureRecognizer];
-
- // Do any additional setup after loading the view.
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
-
- // 键盘高度变化通知,ios5.0新增的
- #ifdef __IPHONE_5_0
- float version = [[[UIDevice currentDevice] systemVersion] floatValue];
- if (version >= 5.0) {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
- }
- #endif
-
- // self.pdfScrollView.contentSize = self.pdfScrollView.frame.size;
-
- [self refreshControl];
- }
- -(void) viewWillDisappear:(BOOL)animated
- {
- [self.hotTextView endEditing:true];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- -(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);
- //}
- //+(CGRect)WindowRect2PDFRect:(CGRect)rect pdf_rect:(CGRect)pdf_rect window_size:(CGSize)window_size
- //{
- // CGRect pdf_expand;
- // float offset_x = 0;
- // float offset_y = 0;
- // float scale =1;
- // if(pdf_rect.size.height>=pdf_rect.size.width)
- // {
- // pdf_expand = CGRectMake(0, 0, pdf_rect.size.height*window_size.width/window_size.height, pdf_rect.size.height);
- // offset_x = (pdf_expand.size.width-pdf_rect.size.width)/2;
- // scale = pdf_rect.size.height/window_size.height;
- //
- // }
- // else
- // {
- // pdf_expand = CGRectMake(0, 0, pdf_rect.size.width, pdf_rect.size.width*window_size.height/window_size.width);
- // offset_y = (pdf_expand.size.height-pdf_rect.size.height)/2;
- // scale = pdf_rect.size.width/window_size.width;
- // }
- // float x=rect.origin.x*scale-offset_x;
- // float y=rect.origin.y*scale-offset_y;
- // float width = rect.size.width*scale;
- // float height = rect.size.height*scale;
- //
- // return CGRectMake(x, y, width, height);
- //
- //}
- -(CGRect) scaleControl:(CGRect) frame from:(CGSize)fwindowsize to:(CGSize)twindowsize
- {
- CGRect pdfsize=CGPDFPageGetBoxRect(self.pageRef, kCGPDFMediaBox);
- frame=[PDFUtils WindowRect2PDFRect:frame pdf_rect:pdfsize window_size:fwindowsize];
-
- frame= [PDFUtils PDFRect2WindowRect:frame pdf_rect:pdfsize window_size:twindowsize];
-
- return frame;
-
- }
- -(void) initControl
- {
- // return;
- 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];
-
- }
- else if([control[@"type"] isEqualToString:@"DatePicker"])
- {
- [self addDatePicker:control destView:self.editControlView index:i];
-
- }
- }
-
- }
- -(void) refreshControl
- {
- int count = [self.controlTemplate[@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSString* controlname =[NSString stringWithFormat:@"control_%d",i];
- NSMutableDictionary * control =self.controlTemplate [ controlname];
-
-
- // if([control[@"type"] isEqualToString:@"TextView"])
- // {
- // UITextView* tv = (UITextView*) [self findControl:controlname];
- // tv.text = control[@"value"];
- // }
- // 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"])
- {
- TouchImageView* btn = (TouchImageView*) [self findControl:controlname];
- NSString* file =control[@"value"];
-
- NSData* img_data=[ImageUtils load_img:file];
-
- if(img_data!=nil)
- {
-
- UIImage* image=[UIImage imageWithData:img_data];
- btn.image = image;
-
- }
-
- }
- // 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];
- //
- // }
- // else if([control[@"type"] isEqualToString:@"DatePicker"])
- // {
- // [self addDatePicker:control destView:self.editControlView index:i];
- //
- // }
- }
- }
- -(void)EndEditing
- {
- [[self view] endEditing:YES];
- }
- #pragma mark add controls
- -(bool) checkActionCondition:(NSString*) condition
- {
- if([condition isEqualToString:@"true"])
- return true;
- if([condition isEqualToString:@"control_18:[value]==0"])
- {
- NSArray* arr= self.controlTemplate[@"control_18"][@"value"];
- if(arr.count==0)
- return false;
- else
- return [arr[0] intValue]==0;
- }
-
- return false;
- }
- -(UIView*) findControl:(NSString*)controlName
- {
- controlName=[controlName stringByReplacingOccurrencesOfString:@"control_" withString:@""];
- int d_idx = [controlName intValue];
- return [self.view viewWithTag:d_idx+CONTROL_BASE];
- }
- -(void) addTextView:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
- {
-
- CGRect srect=[self scaleControl:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue]) from:CGSizeMake(768, 960.5) to:destView.frame.size];
-
- UITextView* tv = [[UITextView alloc] initWithFrame:srect];
- float fontsize = [template[@"size"] floatValue];
- if(fontsize==0)
- fontsize=10;
- [tv setFont:[UIFont systemFontOfSize:fontsize]];
- bool isdisable = [template[@"disable"] boolValue];
-
- tv.editable = !isdisable;
- NSString* text= template[@"value"];
- if(text.length==0)
- text=@" ";
- tv.text =text;
-
- float tv_vmargin= [template[@"tv_vmargin"] floatValue];
- NSString* capital= template[@"capital"];
- UITextAutocapitalizationType capitalType=UITextAutocapitalizationTypeWords;
- if([capital isEqualToString:@"charater"])
- {
- capitalType=UITextAutocapitalizationTypeAllCharacters;
- }
- else if([capital isEqualToString:@"sentences"])
- {
- capitalType=UITextAutocapitalizationTypeSentences;
- }
- else if([capital isEqualToString:@"none"])
- {
- capitalType=UITextAutocapitalizationTypeNone;
- }
- else
- {
- capitalType=UITextAutocapitalizationTypeWords;
- }
-
- tv.autocapitalizationType=capitalType;
-
- NSMutableAttributedString* attr_str= [tv.attributedText mutableCopy];
-
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
- if(tv_vmargin!=0)
- paragraphStyle.lineHeightMultiple = tv_vmargin;
- // paragraphStyle.maximumLineHeight = 25.f;
- // paragraphStyle.minimumLineHeight = 15.f;
- // paragraphStyle.firstLineHeadIndent = 20.f;
- // paragraphStyle.alignment = NSTextAlignmentJustified;
- [attr_str addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,attr_str.length)];
-
- tv.attributedText=attr_str;
- if([text isEqualToString:(@" ")])
- tv.text=@"";
-
- tv.tag = index+ CONTROL_BASE;
-
-
- tv.scrollEnabled=false;
-
- NSString* tv_format=template[@"keyboard"];
- if([tv_format isEqualToString:@"tel"])
- {
- tv.keyboardType=UIKeyboardTypePhonePad;
- }
- else if([tv_format isEqualToString:@"number"])
- {
- tv.keyboardType=UIKeyboardTypeNumberPad;
- }
- else if([tv_format isEqualToString:@"email"])
- {
- tv.keyboardType=UIKeyboardTypeEmailAddress;
- }
- else
- {
- tv.keyboardType=UIKeyboardTypeDefault;
- }
-
-
- //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
- {
- CGRect srect=[self scaleControl:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue]) from:CGSizeMake(768, 960.5) to:destView.frame.size];
- UILabel* label = [[UILabel alloc] initWithFrame:srect];
- 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
- {
- CGRect srect=[self scaleControl:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue]) from:CGSizeMake(768, 960.5) to:destView.frame.size];
- UIButton* btn = [[UIButton alloc] initWithFrame:srect];
- [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];
- }
- -(void) addDatePicker:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
- {
- CGRect srect=[self scaleControl:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue]) from:CGSizeMake(768, 960.5) to:destView.frame.size];
- UIButton* btn = [[UIButton alloc] initWithFrame:srect];
-
- [btn setTitle:template[@"value"] forState:UIControlStateNormal];
- float fontsize = [template[@"size"] floatValue];
- if(fontsize==0)
- fontsize=10;
- btn.titleLabel.font = [UIFont systemFontOfSize: fontsize];
- btn.tag = index+ CONTROL_BASE;
- [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
- btn.backgroundColor = UIColorFromRGB(BT_BG);
- [btn addTarget:self action:@selector(ControlDatePickerClicked:) 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 destView:(UIView*)destView
- {
-
-
- CGRect srect=[self scaleControl:CGRectMake(x,y,size,size) from:CGSizeMake(768, 960.5) to:destView.frame.size];
- UIView* v=[[UIView alloc] initWithFrame:srect];
- return v;
-
- }
- -(void) addCheck:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
- {
-
- CGRect srect=[self scaleControl:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue]) from:CGSizeMake(768, 960.5) to:destView.frame.size];
- UIButton* btn = [[UIButton alloc] initWithFrame:srect];
-
- // 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"];
- float fontsize = [template[@"size"] floatValue];
- if(fontsize==0)
- fontsize=10;
- // 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];
- NSArray* checkmarker = item[1];
- if(checkmarker.count==0)
- {
- [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- btn.titleLabel.font = [UIFont systemFontOfSize: fontsize];
- btn.backgroundColor = UIColorFromRGB(CK_BG);
- if([checkedData containsObject:[NSNumber numberWithLong:i]])
- {
- [btn setTitle:item[0][0] forState:UIControlStateNormal];
-
- }
- continue;
- }
- else
- {
- [btn setTitle:@"" forState:UIControlStateNormal];
- }
- UIView* marker=[self createMarker:[template[@"marker_size"] intValue] x:[item[1][0] intValue] y:[item[1][1] intValue] destView:destView];
-
- 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
- {
- CGRect srect=[self scaleControl:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue]) from:CGSizeMake(768, 960.5) to:destView.frame.size];
- TouchImageView* btn = [[TouchImageView alloc] initWithFrame:srect];
-
- 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
- {
- CGRect srect=[self scaleControl:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue]) from:CGSizeMake(768, 960.5) to:destView.frame.size];
- UIImageView* btn = [[UIImageView alloc] initWithFrame:srect];
-
- 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:(nullable UIView *)view atScale:(CGFloat)scale
- {
- CGPoint contentOffsetPoint = self.pdfScrollView.contentOffset;
- CGSize contentSize =self.pdfScrollView.contentSize;//frame.size;
- // CGSize size1 = self.pdfScrollView.bounds.size;
- // NSLog(@"frame:%@ bound:%@", NSStringFromCGSize(contentSize),NSStringFromCGSize(size1) );
- contentSize.height+=self.keyboard_h;
- contentOffsetPoint.y+=self.keyboard_h;
-
-
-
- self.pdfScrollView.contentSize =contentSize;
- self.pdfScrollView.contentOffset=contentOffsetPoint;
- }
- //- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
- //
- //
- //
- //}
- #pragma mark Button Click
- - (void)ControlDatePickerClicked:(UIButton *)sender {
-
-
- long index = sender.tag - CONTROL_BASE;
-
- __weak __typeof(self)weakSelf = self;
- NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
- [formatter setDateFormat:@"MM/dd/yyyy"];
- NSString* date = sender.currentTitle;
-
- NSDate* currentDate =nil;
- if(date.length==0)
- currentDate=[NSDate date];
- else
- currentDate=[formatter dateFromString:date];
-
- DatePickerViewController* dpvc =[ [UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"DatePickerViewController"];
-
- dpvc.pickerMode = UIDatePickerModeDate;
-
-
-
- dpvc.date = currentDate;
- dpvc.formatter = formatter;
- dpvc.labelTime.text = [formatter stringFromDate:currentDate];
-
- dpvc.blk_Set = ^(NSString* strdate)
- {
- // weakSelf.labelSignDate.text = strdate;
-
- [sender setTitle:strdate forState:UIControlStateNormal];
-
- weakSelf.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = strdate;
- };
- dpvc.title=@"Please choose a date";
- [self.navigationController pushViewController:dpvc animated:true];
- }
- - (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;
-
-
-
- NSArray* item = rowData[i];
- NSArray* checkmarker = item[1];
- if(checkmarker.count==0)
- {
- sender.backgroundColor = UIColorFromRGB(CK_BG);
- if([checkedData containsObject:[NSNumber numberWithLong:i]])
- {
- [sender setTitle:item[0][0] forState:UIControlStateNormal];
- if(item.count>=3)
- {
- NSMutableDictionary* action = item[2];
- NSArray* disable_arr = action[@"disable"] ;
- for(int d = 0 ; d<disable_arr.count;d++)
- {
- self.controlTemplate [disable_arr[d] ] [@"disable"] = [NSNumber numberWithBool:true];
- NSString* s_idx =disable_arr[d];
- s_idx=[s_idx stringByReplacingOccurrencesOfString:@"control_" withString:@""];
- int d_idx = [s_idx intValue];
- ((UITextView*)[sender.superview viewWithTag:d_idx+CONTROL_BASE]).editable = false;
- }
- NSArray* enable_arr = action[@"enable"] ;
- for(int e = 0 ; e<enable_arr.count;e++)
- {
- self.controlTemplate [enable_arr[e] ] [@"disable"] = [NSNumber numberWithBool:false];
-
- NSString* s_idx =enable_arr[e];
- s_idx=[s_idx stringByReplacingOccurrencesOfString:@"control_" withString:@""];
- int d_idx = [s_idx intValue];
- ((UITextView*)[sender.superview viewWithTag:d_idx+CONTROL_BASE]).editable = true;
- }
-
- NSMutableDictionary* json_setval=action[@"set_val"] ;
- for(int i=0;i<[json_setval[@"count"] intValue];i++)
- {
-
- NSMutableDictionary * control = json_setval [[NSString stringWithFormat:@"item_%d",i] ];
- UITextView* tv = (UITextView*) [self findControl:control[@"control"]];
- NSString* value = control[@"value"];
-
- UITextView* tv6 = (UITextView*) [self findControl:@"control_6"];
- NSString* text = tv6.text;
- NSString* newvalue = nil;
- if([value isEqualToString:@"*0.1"])
- {
-
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
- formatter.numberStyle =kCFNumberFormatterCurrencyStyle;
- NSString* prefix_str= self.controlTemplate [control[@"control"] ][@"prefix_str"];
- if(prefix_str.length==0)
- prefix_str = @"";
- text=[text stringByReplacingOccurrencesOfString:prefix_str withString:@"$"];
- double f = [[formatter numberFromString:text] doubleValue]*0.1;
- newvalue = [formatter stringFromNumber:[NSNumber numberWithDouble: f]];
-
- newvalue=[newvalue stringByReplacingOccurrencesOfString:@"$" withString:prefix_str];
- // float f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue]*0.1;
- // newvalue = [NSString stringWithFormat:@"$ %.2f",f];
- self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
- }
- else if([value isEqualToString:@"*0.9"])
- {
- // float f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue]*0.9;
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
- formatter.numberStyle =kCFNumberFormatterCurrencyStyle;
- NSString* prefix_str= self.controlTemplate [control[@"control"] ][@"prefix_str"];
- if(prefix_str.length==0)
- prefix_str = @"";
- text=[text stringByReplacingOccurrencesOfString:prefix_str withString:@"$"];
- double f = [[formatter numberFromString:text] doubleValue]*0.9;
- newvalue = [formatter stringFromNumber:[NSNumber numberWithDouble: f]];
- newvalue=[newvalue stringByReplacingOccurrencesOfString:@"$" withString:prefix_str];
- // newvalue = [NSString stringWithFormat:@"$ %.2f",f];
- self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
- }
-
- tv.text = newvalue;
-
- }
- }
-
- }
- continue;
- }
- else
- {
- [sender setTitle:@"" forState:UIControlStateNormal];
- }
-
- // 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
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
- long index = textView.tag - CONTROL_BASE;
- if([text isEqualToString:@""])
- return true;
-
- if([text isEqualToString:@"\n"])
- {
- [textView resignFirstResponder];
- return false;
- }
-
- NSString* tv_format=self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"format"];
- if([tv_format isEqualToString:@"us_tel"])
- {
- NSMutableString *newString = [[textView.text stringByReplacingCharactersInRange:range withString:text] mutableCopy];
- NSArray *components = [newString componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
- NSString *decimalString = [components componentsJoinedByString:@""];
-
- NSUInteger length = decimalString.length;
- BOOL hasLeadingOne = length > 0 && [decimalString characterAtIndex:0] == '1';
-
- if (length == 0 ) {
- textView.text = decimalString;
- return NO;
- }
- if((length >= 10 && !hasLeadingOne) )
- {
- if(length>15)
- return NO;
- // newString=[[newString stringByReplacingOccurrencesOfString:@"-" withString:@""] mutableCopy];
- // [newString insertString:@"-" atIndex:14];
- // textView.text = newString;
- // return NO;
- }
- if((length >= 11))
- {
- if(length>16)
- return NO;
- // newString=[[newString stringByReplacingOccurrencesOfString:@"-" withString:@""] mutableCopy];
- // [newString insertString:@"-" atIndex:16];
- // textView.text = newString;
- // return NO;
- }
- NSUInteger index = 0;
- NSMutableString *formattedString = [NSMutableString string];
-
- if (hasLeadingOne) {
- [formattedString appendString:@"1 "];
- index += 1;
- }
-
- if (length - index > 3) {
- NSString *areaCode = [decimalString substringWithRange:NSMakeRange(index, 3)];
- [formattedString appendFormat:@"(%@) ",areaCode];
- index += 3;
- }
-
- if (length - index > 3) {
- NSString *prefix = [decimalString substringWithRange:NSMakeRange(index, 3)];
- [formattedString appendFormat:@"%@ ",prefix];
- index += 3;
- }
-
- if (length - index > 4) {
- NSString *prefix = [decimalString substringWithRange:NSMakeRange(index, 4)];
- [formattedString appendFormat:@"%@-",prefix];
- index += 4;
- }
-
- NSString *remainder = [decimalString substringFromIndex:index];
- [formattedString appendString:remainder];
-
- textView.text = formattedString;
-
- return NO;
- }
- else if([tv_format isEqualToString:@"price"])
- {
- // NSMutableString *newString = [[textView.text stringByReplacingCharactersInRange:range withString:text] mutableCopy];
- // NSArray *components = [newString componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
- // NSString *decimalString = [components componentsJoinedByString:@""];
- //
- //
- //
-
-
- //
- // NSString *newprice = [formatter stringFromNumber:[NSNumber numberWithInt: [decimalString intValue]]];
- //
- // textView.text = newprice;
-
-
-
- NSCharacterSet *cs;
- cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
- //
- NSString *filtered = [[text componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
-
- BOOL canChange = [text isEqualToString:filtered];
- // if(canChange)
- // {
- //
- // }
- return canChange;
-
- // return NO;
- }
- else
- {
- NSString* oldtext =textView.text;
- if(oldtext==nil)
- oldtext=@"";
-
- bool canChange=true;
-
- int max_line = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"lines"] intValue];
- if(max_line==0)//默认只能有一行
- max_line=1;
- long linecount=[TextUtils countOccurencesOfString:oldtext find:@"\n"];
- if(max_line!=-1) //maxline -1表示不限制行数。
- {
- if(linecount<=max_line-1&& [text isEqualToString:@"\n"])
- {
- canChange = false;
- }
- }
-
- int lenth = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"length"] intValue];
- if(lenth==0)
- return canChange;
- else
- {
- return canChange&& (lenth>textView.text.length ||[text isEqualToString:@""]);
- }
- }
-
- }
- //- (void)textViewDidBeginEditing:(UITextView *)textView
- //{
- // self.hotTextView = textView;
- //}
- - (void)textViewDidBeginEditing:(UITextView *)textView
- {
- long index = textView.tag - CONTROL_BASE;
- NSString* tv_format=self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"format"];
- if([tv_format isEqualToString:@"price"])
- {
-
- NSString* prefix_str= self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"prefix_str"];
- if(prefix_str.length==0)
- prefix_str = @"";
-
-
- NSString* text =[textView.text stringByReplacingOccurrencesOfString:prefix_str withString:@"$"];
-
-
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
-
- formatter.numberStyle =kCFNumberFormatterCurrencyStyle;
- NSNumber* number= [formatter numberFromString:text];
- if(number!=nil)
- textView.text = [NSString stringWithFormat:@"%.2f",[number doubleValue]];
- }
-
- // NSRange r = textView.selectedRange;
- //
- //
- // textView.selectedRange = NSMakeRange(textView.text.length, 0);
- // NSRange range;
- //
- // range.location = textView.text.length;
- //
- // range.length = 0;
- //
- // textView.selectedRange = range;
-
- }
- - (BOOL)textViewShouldBeginEditing:(UITextView *)textView
- {
-
- NSLog(@"textViewShouldBeginEditing");
-
- self.hotTextView = textView;//(UITableViewCell*)textView.superview.superview;
-
-
-
-
-
-
- return textView.editable;
- }
- - (void)textViewDidEndEditing:(UITextView *)textView
- {
-
- long index = textView.tag - CONTROL_BASE;
-
-
- //处理 prefix 和 浮点格式化
- NSString* prefix_str= self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"prefix_str"];
- if(prefix_str.length==0)
- prefix_str = @"";
- NSString* text =textView.text;// [textView.text stringByReplacingOccurrencesOfString:prefix_str withString:@""];
-
- NSString* value_type= self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value_type"];
- if([value_type isEqualToString:@"float"])
- text=[NSString stringWithFormat:@"%.2f",[text doubleValue] ];
-
- // text =[NSString stringWithFormat:@"%@%@",prefix_str,text] ;
-
-
- if([self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"format"] isEqualToString:@"price"])
- {
- text =textView.text;
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
-
- formatter.numberStyle =kCFNumberFormatterCurrencyStyle;
-
-
- NSNumber * nprice =[NSNumber numberWithDouble: [text doubleValue]];
- if(text.length==0)
- nprice=nil;
- text = [formatter stringFromNumber:nprice];
- text=[text stringByReplacingOccurrencesOfString:@"$" withString:prefix_str];
- // textView.text = newprice;
- // return NO;
- }
-
-
- textView.text = text;
-
- if(text==nil)
- text=@"";
- self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = text;
-
- NSDictionary* action = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"action"];
- NSArray* keys=[action allKeys];
- for(int k=0;k<keys.count;k++)
- {
- NSMutableDictionary* act_k = action[keys[k] ];
-
-
- if (![self checkActionCondition:act_k[@"condition"]])
- continue;
- for(int i=0;i<[act_k[@"count"] intValue];i++)
- {
-
- NSMutableDictionary * control = act_k [[NSString stringWithFormat:@"item_%d",i] ];
- UITextView* tv = (UITextView*) [self findControl:control[@"control"]];
- NSString* value = control[@"value"];
-
- NSString* newvalue = nil;
- if([value isEqualToString:@"*0.1"])
- {
- // double f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] doubleValue]*0.1;
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
- formatter.numberStyle =kCFNumberFormatterCurrencyStyle;
-
- NSString* prefix_str= self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"prefix_str"];
- if(prefix_str.length==0)
- prefix_str = @"";
-
- if(text.length==0)
- {
- newvalue=nil;
- }
- else
- {
- text=[text stringByReplacingOccurrencesOfString:prefix_str withString:@"$"];
- double f = [[formatter numberFromString:text] doubleValue]*0.1;
-
- // if(tv==self.hotTextView)
- // {
- //
- // newvalue = [NSString stringWithFormat:@"%.2f",f];
- // }
- // else
- {
- newvalue = [formatter stringFromNumber:[NSNumber numberWithDouble: f]];
- newvalue=[newvalue stringByReplacingOccurrencesOfString:@"$" withString:prefix_str];
- // newvalue = [NSString stringWithFormat:@"$ %.2f",f];
- }
- }
-
- self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
- }
- else if([value isEqualToString:@"*0.9"])
- {
- // double f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] doubleValue]*0.9;
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
- formatter.numberStyle =kCFNumberFormatterCurrencyStyle;
-
- NSString* prefix_str= self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"prefix_str"];
- if(prefix_str.length==0)
- prefix_str = @"";
-
- if(text.length==0)
- {
- newvalue=nil;
- }
- else
- {
- text=[text stringByReplacingOccurrencesOfString:prefix_str withString:@"$"];
- double f = [[formatter numberFromString:text] doubleValue]*0.9;
- newvalue = [formatter stringFromNumber:[NSNumber numberWithDouble: f]];
- newvalue=[newvalue stringByReplacingOccurrencesOfString:@"$" withString:prefix_str];
- }
- // newvalue = [NSString stringWithFormat:@"$ %.2f",f];
- self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
- }
- else if([value isEqualToString:@"control_6-control_7"])
- {
-
- UITextView* tv6 = (UITextView*) [self findControl:@"control_6"];
- // float f6= [[tv6.text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue];
- //
- // float f7= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue];
-
-
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
- formatter.numberStyle =kCFNumberFormatterCurrencyStyle;
-
- NSString* prefix_str= self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"prefix_str"];
- if(prefix_str.length==0)
- prefix_str = @"";
- NSString * text6=[tv6.text stringByReplacingOccurrencesOfString:prefix_str withString:@"$"];
- text=[text stringByReplacingOccurrencesOfString:prefix_str withString:@"$"];
- double f6 =0.0;
- // if(tv6==self.hotTextView)
- // f6=[tv6.text doubleValue];
- // else
- f6=[[formatter numberFromString:text6] doubleValue];
- double f7 = [[formatter numberFromString:text] doubleValue];
- newvalue = [formatter stringFromNumber:[NSNumber numberWithDouble: f6-f7]];
- newvalue=[newvalue stringByReplacingOccurrencesOfString:@"$" withString:prefix_str];
- // newvalue = [NSString stringWithFormat:@"$ %.2f",f6-f7];
- self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
- }
-
- tv.text = newvalue;
-
- }
- }
-
- // 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;");
-
- __weak __typeof(self)weakSelf = self;
- {
-
- long index = touchImageView.tag - CONTROL_BASE;
-
-
- NSMutableDictionary* control_json = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ];
-
-
- // 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.subType = control_json[@"name"];
- signatureVC.can_fill= [control_json[@"can_fill"] boolValue];
- signatureVC.signature_ratio= touchImageView.frame.size;
-
- // 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;
- weakSelf.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
-
- }
- };
- signatureVC.blk_Fill =^(NSString* file,bool fillFullDoc)
- {
-
- if(weakSelf.blk_Fill)
- weakSelf.blk_Fill(file,control_json[@"name"],fillFullDoc);
- // for(int j=0;j<[self.controlTemplate[@"count"] intValue];j++)
- // {
- // NSMutableDictionary* dest =self.controlTemplate[[NSString stringWithFormat:@"control_%d",j]];
- // NSString* type = dest[@"type"];
- // if(![type isEqualToString:@"Signature"])
- // continue;
- // if([dest[@"name"] isEqualToString:control_json[@"name"]])
- // {
- // dest[@"value"]=file;
- // }
- // }
- [weakSelf refreshControl];
-
- // // 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.title =[NSString stringWithFormat:@"Signature: %@",control_json[@"name"]];
- vc.signature_ratio= touchImageView.frame.size;
- vc.linewidth = [control_json[@"linewidth"] intValue];
- vc.onReturnImg = ^(UIImage* img)
- {
-
-
- signimg = img;
-
- if(signimg!=nil)
- {
- NSString* file=[PDFUtils addSignature:signimg to:self.signatureData subType:control_json[@"name"]];
- 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;
- //
-
- }
- #pragma mark Responding to keyboard events
- - (CGRect)relativeFrameForScreenWithView:(UIView *)v
- {
- UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
- CGRect rect=[v convertRect: v.bounds toView:window];
- return rect;
-
-
- // BOOL iOS7 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 7;
- //
- // CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
- // if (!iOS7) {
- // screenHeight -= 20;
- // }
- // UIView *view = v;
- // CGFloat x = .0;
- // CGFloat y = .0;
- // while (view.frame.size.width != 320 || view.frame.size.height != screenHeight) {
- // x += view.frame.origin.x;
- // y += view.frame.origin.y;
- // view = view.superview;
- // if ([view isKindOfClass:[UIScrollView class]]) {
- // x -= ((UIScrollView *) view).contentOffset.x;
- // y -= ((UIScrollView *) view).contentOffset.y;
- // }
- // }
- // return CGRectMake(x, y, v.frame.size.width, v.frame.size.height);
- }
- - (void)keyboardWillChangeFrame:(NSNotification *)notification {
- NSLog(@"keyboardWillChangeFrame");
- }
- - (void)keyboardWillShow:(NSNotification *)notification {
- NSLog(@"keyboardWillShow");
-
- if(self.keyboard_show)
- return;
-
- self.keyboard_show=true;
- /*
- Reduce the size of the text view so that it's not obscured by the keyboard.
- Animate the resize so that it's in sync with the appearance of the keyboard.
- */
-
- NSDictionary *userInfo = [notification userInfo];
-
- NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
- CGSize keyboardSize = [aValue CGRectValue].size;
- NSLog(@"keyboard height:%f",keyboardSize.height);
-
- CGRect cellrect_screen = [self relativeFrameForScreenWithView:self.hotTextView];
- CGRect rect_screen = [ UIScreen mainScreen ].bounds;
- int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height;
- if(cellpos>rect_screen.size.height-keyboardSize.height)
- {
- // self.resize = true;
-
- self.keyboard_h =keyboardSize.height;
- CGPoint contentOffsetPoint = self.pdfScrollView.contentOffset;
- CGSize contentSize =self.pdfScrollView.contentSize;//frame.size;
- CGSize size1 = self.pdfScrollView.bounds.size;
- NSLog(@"frame:%@ bound:%@", NSStringFromCGSize(contentSize),NSStringFromCGSize(size1) );
- contentSize.height+=self.keyboard_h;
- contentOffsetPoint.y+=self.keyboard_h;
-
-
-
- self.pdfScrollView.contentSize =contentSize;
- self.pdfScrollView.contentOffset=contentOffsetPoint;
-
- }
-
-
- // self.pdfScrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-self.keyboard_h);
-
- // CGSize tablecontent =self.editorTable.contentSize;
- // tablecontent.height=tablecontent.height+self.keyboard_h;
- // self.editorTable.contentSize=tablecontent;
- // }
- // Animate the resize of the text view's frame in sync with the keyboard's appearance.
- // [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration];
- }
- - (void)keyboardWillHide:(NSNotification *)notification {
- NSLog(@"keyboardWillHide");
-
- self.keyboard_show=false;
- // NSDictionary* userInfo = [notification userInfo];
-
- /*
- Restore the size of the text view (fill self's view).
- Animate the resize so that it's in sync with the disappearance of the keyboard.
- */
- // NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
- // NSTimeInterval animationDuration;
- // [animationDurationValue getValue:&animationDuration];
-
-
- CGPoint contentOffsetPoint = self.pdfScrollView.contentOffset;
- CGSize contentSize =self.pdfScrollView.contentSize;//frame.size;
- contentSize.height-=self.keyboard_h;
-
- contentOffsetPoint.y-=self.keyboard_h;
-
- self.pdfScrollView.contentSize=contentSize;
- self.pdfScrollView.contentOffset=contentOffsetPoint;
- // CGSize tablecontent =self.pdfScrollView.contentSize;
- // tablecontent.height=tablecontent.height-self.keyboard_h;
- // self.editorTable.contentSize=tablecontent;
-
- // self.pdfScrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
-
- self.keyboard_h= 0;
- // NSLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
-
-
- // if(self.resize)
- // {
- // NSTimeInterval animationDuration = 0.30f;
- // CGRect frame = self.view.frame;
- // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
- // // { //还原界面
- // // moveY = prewMoveY;
- // frame.origin.y +=self.ioffset;
- // frame.size. height -=self.ioffset;
- // self.view.frame = frame;
- // // }
- // //self.view移回原位置
- // [UIView beginAnimations:@"ResizeView" context:nil];
- // [UIView setAnimationDuration:animationDuration];
- // self.view.frame = frame;
- // [UIView commitAnimations];
- // //[textField resignFirstResponder];
- // self.ioffset=0;
- // }
-
-
- // [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];
- }
- @end
|