| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450 |
- //
- // 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 "RAUtils.h"
- #import "AppDelegate.h"
- #import "TouchLabel.h"
- #import "EnumSelectViewController.h"
- typedef enum {
- ScreenOrientationUnknown = 0,
- ScreenOrientationPortrait = 1,
- ScreenOrientationLand = 3
- }ScreenOrientation;
- //#import "TouchImageView.h"
- @interface PageViewController ()
- @property (nonatomic,assign) ScreenOrientation orientation;
- @property (nonatomic,assign) ScreenOrientation currentAppOrientation;
- @end
- @implementation PageViewController
- - (BOOL)canBecomeFirstResponder{
- return YES;
- }
- //- (IBAction)onBtnClick:(id)sender {
- // [self becomeFirstResponder];
- // UIView* v = sender;
- //
- // UIMenuItem *detail = [[UIMenuItem alloc] initWithTitle:@"abc" action:@selector(showDetail:)];
- // // [detail setValue:_id forKey:@"_id"];
- //
- // UIMenuController *menu = [UIMenuController sharedMenuController];
- //
- // [menu setMenuItems:[NSArray arrayWithObjects:detail, nil]];
- //
- // [menu setTargetRect:v.frame inView:v.superview];
- // [menu setMenuVisible:YES animated:YES];
- //}
- - (ScreenOrientation)currentAppOrientation {
- CGSize screenSize = [UIScreen mainScreen].bounds.size;
- if (screenSize.width > screenSize.height) return ScreenOrientationLand;
- return ScreenOrientationPortrait;
- }
- - (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.pdfScrollView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
- // [self initControl];
-
- // UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc]
- // initWithTarget:self
- // action:@selector(handlePinch:)];
- //
- // [self.view addGestureRecognizer:pinchGestureRecognizer];
-
- // Do any additional setup after loading the view.
- self.orientation = ScreenOrientationUnknown;
-
- // self.pdfScrollView.backgroundColor = [UIColor redColor];
- // [self.pdfScrollView viewWithTag:1024].backgroundColor = [UIColor orangeColor];
- // self.pdfPageView.backgroundColor = [UIColor yellowColor];
- // self.editControlView.backgroundColor = [UIColor colorWithRed:0.4 green:0.8 blue:0.3 alpha:0.5];
- //
- // [self.pdfPageView removeFromSuperview];
- // [self.editControlView removeFromSuperview];
- // self.view.backgroundColor = [UIColor blueColor];
- }
- -(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;
-
-
-
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- if (self.orientation != ScreenOrientationUnknown) {
- if (self.orientation == self.currentAppOrientation) {
- // 修复未完全显示时停止拖动,再进入该页面就不会生成Control控件
- if (self.editControlView.subviews.count) {
- [self refreshControl];
- } else {
- [self initControl];
- }
-
-
- } else {
- [self rotateView];
- }
- } else {
- [self initControl];
- }
- [self.parentViewController.view layoutIfNeeded];
- }
- - (void)viewWillLayoutSubviews {
-
- /*
- * 解决旋转后第二个视图覆盖部分当前视图
- */
-
- [self clearControlView];
-
- self.pdfScrollView.scrollEnabled = NO;
- // root
- [self updateView:self.view];
-
- // scroll
- [self updateView:self.pdfScrollView];
-
- // 1024 view
- [self updateView:[self.pdfScrollView viewWithTag:1024]];
-
- // pdf
- [self updateView:self.pdfPageView];
- // DebugLog(@"pdf page frame %@",[NSValue valueWithCGRect:self.pdfPageView.frame]);
- [self.pdfPageView setNeedsDisplay];
-
- // edit
- [self updateView:self.editControlView];
-
- // contentSize
- self.pdfScrollView.contentSize = [self.pdfScrollView viewWithTag:1024].bounds.size;
- self.pdfScrollView.contentOffset = CGPointZero;
-
- [self initControl];
-
- [self.view setNeedsDisplay];
-
- self.pdfScrollView.scrollEnabled = YES;
-
- }
- - (void)clearControlView {
- for (UIView * v in self.editControlView.subviews)
- {
- [v removeFromSuperview ];
- }
- }
- - (void)rotateView {
- if (self.orientation == self.currentAppOrientation) return;
- [self viewWillLayoutSubviews];
-
- self.orientation = self.currentAppOrientation;
-
- for (UIViewController *vc in self.parentViewController.childViewControllers) {
- [vc viewWillLayoutSubviews];
- }
-
- }
- - (void)updateView:(UIView *)view {
- // return;
- if (!view) return;
- CGRect frame = [UIScreen mainScreen].bounds;
-
- if (view == self.view) {
-
- } else if (view == self.pdfScrollView) {
- frame.origin.y = 64;
- frame.size.height -= 64;
- self.pdfScrollView.contentSize = CGSizeZero;
- } else {
- frame.size.height -= 64;
- view.transform = CGAffineTransformIdentity; // 解决缩放后,旋转屏幕。产生偏差(ContentSize和ContentOffset)
- }
-
- view.frame = frame;
- view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
-
- [view layoutIfNeeded];
- [view setNeedsDisplay];
- }
- -(void) viewWillDisappear:(BOOL)animated
- {
- [self.hotTextView endEditing:true];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- self.orientation = self.currentAppOrientation;
- }
- -(void) refreshPage
- {
- [self viewDidLoad];
- [self.pdfPageView setNeedsDisplay];
- // [self viewDidAppear:YES];
- }
- -(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
- {
-
- if(self.hide_control)
- return;
- // return;
- [self clearControlView]; // fill all时未显示。
- int count = [self.page_controlTemplate[@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * control =self.page_controlTemplate [[NSString stringWithFormat:@"control_%d",i] ];
- if([control[@"type"] isEqualToString:@"TextView"])
- {
- [self addTextView:control destView:self.editControlView index:i];
- }
- if([control[@"type"] isEqualToString:@"TouchLabel"])
- {
- [self addTouchLabel: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.page_controlTemplate[@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSString* controlname =[NSString stringWithFormat:@"control_%d",i];
- NSMutableDictionary * control =self.page_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];
- }
- //-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
- //{
- // if (self.presentedViewController) {
- // [self.presentedViewController dismissViewControllerAnimated:NO completion:nil];
- // }
- //
- //}
- //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
- // [self rotateView];// 在此重新布局使视图在旋转过程中减少卡顿,更自然。
- //}
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
-
- if (self.presentedViewController) {
- [self.presentedViewController dismissViewControllerAnimated:NO completion:nil];
- }
-
- [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
- {
- [self rotateView];// 在此重新布局使视图在旋转过程中减少卡顿,更自然。
- } completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
- {
- }];
-
-
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- }
- //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
- //{
- //
- //// [self rotateView];
- //
- //// [self initControl];
- ////// [self.pdfPageView setNeedsLayout];
- //// [self.pdfPageView setNeedsDisplay];
- ////// UIDeviceOrientation dev_ori = [[UIDevice currentDevice]orientation];
- ////
- ////// UIApplication * app = [UIApplication sharedApplication];
- ////// AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- ////// [appDelegate didRotated];
- ////
- //// // UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
- //// // if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
- //// // {
- //// // self.orientation = orientation;
- //// // [self.collectionview.collectionViewLayout invalidateLayout];
- //// // DebugLog(@"routed");
- //// // }
- ////
- //
- //
- //
- //}
- #pragma mark add controls
- -(bool) checkActionCondition:(NSString*) condition
- {
- if([condition isEqualToString:@"true"])
- return true;
- if([condition isEqualToString:@"false"])
- return false;
- if([condition isEqualToString:@"control_18:[value]==0"])
- {
- NSArray* arr= self.page_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];
- }
- -(UITextView*) findNextTV:(UITextView*)tv
- {
- long index = tv.tag - CONTROL_BASE;
-
-
-
- int count = [self.page_controlTemplate[@"count"] intValue];
- for(long i=index+1;i<count;i++)
- {
- NSMutableDictionary * control =self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",i] ];
- if(![control[@"type"] isEqualToString:@"TextView"])
- {
- continue;
- }
-
- for(UIView*v in self.editControlView.subviews)
- {
- if(v.tag==i+CONTROL_BASE)
- return (UITextView*)v;
- }
-
-
- }
- return nil;
- }
- -(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) to:destView.frame.size];
-
- UITextView* tv = [[UITextView alloc] initWithFrame:srect];
- if([template[@"next_end"] boolValue])
- tv.returnKeyType=UIReturnKeyDefault;
- else
- tv.returnKeyType=UIReturnKeyNext;
- float fontsize = [template[@"size"] floatValue];
- if(fontsize==0)
- fontsize=10;
- if(self.currentAppOrientation==ScreenOrientationLand)
- fontsize=fontsize*0.8; // 缩小字体否则textview显示不下。
- [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];
-
- NSString * alignment=template[@"textAlignment"];
- paragraphStyle.alignment=NSTextAlignmentLeft; // 默认左对齐
- if([alignment.lowercaseString isEqualToString:@"center"])
- paragraphStyle.alignment=NSTextAlignmentCenter;
- else if([alignment.lowercaseString isEqualToString:@"left"])
- paragraphStyle.alignment=NSTextAlignmentLeft;
- else if([alignment.lowercaseString isEqualToString:@"right"])
- paragraphStyle.alignment=NSTextAlignmentRight;
-
- 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) 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]];
-
- NSString * alignment=template[@"textAlignment"];
-
- if([alignment.lowercaseString isEqualToString:@"center"])
- label.textAlignment=NSTextAlignmentCenter;
- else if([alignment.lowercaseString isEqualToString:@"left"])
- label.textAlignment=NSTextAlignmentLeft;
- else if([alignment.lowercaseString isEqualToString:@"right"])
- label.textAlignment=NSTextAlignmentRight;
-
-
- 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) addTouchLabel:(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) to:destView.frame.size];
- TouchLabel * label = [[TouchLabel alloc] initWithFrame:srect] ;
- float fontsize = [template[@"size"] floatValue];
- if(fontsize==0)
- fontsize=10;
- [label setFont:[UIFont systemFontOfSize:fontsize]];
-
- NSString * alignment=template[@"textAlignment"];
-
- if([alignment.lowercaseString isEqualToString:@"center"])
- label.textAlignment=NSTextAlignmentCenter;
- else if([alignment.lowercaseString isEqualToString:@"left"])
- label.textAlignment=NSTextAlignmentLeft;
- else if([alignment.lowercaseString isEqualToString:@"right"])
- label.textAlignment=NSTextAlignmentRight;
- label.backgroundColor = UIColorFromRGB(TV_BG);//[UIColor lightGrayColor];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(LabelTap:)];
- // tap.minimumPressDuration = 0.8; //定义按的时间
- [label addGestureRecognizer:tap];
- 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)LabelTap:(UILongPressGestureRecognizer*)gestureRecognizer {
-
- long index = gestureRecognizer.view.tag - CONTROL_BASE;
-
-
- DebugLog(@"LabelTap tag = %ld",index);
-
- NSMutableDictionary* control_json = self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ];
-
-
-
- NSString* action = control_json[@"action"];
- if ([action isEqualToString:@"enum"])
- {
- NSMutableDictionary* cadedate = control_json[@"cadedate"];
-
-
- EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
-
- enumvc.max_select = 1;
-
-
- enumvc.cadedate = cadedate;
- enumvc.title = @"";
-
-
- enumvc.single_select =true;
-
- // __weak typeof(self) weakSelf = self;
-
- enumvc.returnValue = ^(NSMutableDictionary* value){
- control_json[@"cadedate"]=value;
- int count = [[value valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSDictionary* val_json =[value objectForKey:[NSString stringWithFormat:@"val_%d",i]];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- TouchLabel* label = (TouchLabel*)gestureRecognizer.view;
- label.text = [val_json valueForKey:@"value"];
- control_json[@"value"]= [val_json valueForKey:@"value"];
- break;
- }
- }
-
- // if (weakSelf) {
- // __strong typeof(weakSelf) strongSelf = weakSelf;
- // [strongSelf changePriceType:[strongSelf checkedCadedate:value]];
- // }
-
- };
-
- [self presentViewController:enumvc animated:true completion:nil];
-
- }
-
-
-
-
-
- // if(gestureRecognizer.view.tag - self.basetag < MAX_COLUMN) //header
- // return;
-
- // [UIView beginAnimations:nil context:nil];
- // [UIView setAnimationDuration:0.65];
- // long row = gestureRecognizer.view.tag/self.column_count;
- // long column = gestureRecognizer.view.tag%self.column_count;
- // if(self.fullrowselect)
- // {
- //
- // for(int i=0;i<self.column_count;i++)
- // {
- // [self viewWithTag:(row*self.column_count+i)].alpha = 0.5;
- // }
- // for(int i=0;i<self.column_count;i++)
- // {
- // [self viewWithTag:(row*self.column_count+i)].alpha = 1.0;
- // }
- //
- // }
- // else
- // {
- // gestureRecognizer.view.alpha=0.5;
- // gestureRecognizer.view.alpha=1;
- //
- // }
- // [UIView commitAnimations];
- //
- //
- // if(self.fullrowselect)
- // {
- // if (self.griddelegate && [self.griddelegate respondsToSelector:@selector(Tap:row:)])
- // [griddelegate Tap:gestureRecognizer.view row:row];
- // }
- // else
- // if (self.griddelegate && [self.griddelegate respondsToSelector:@selector(Tap:row:column:)])
- // [griddelegate Tap:gestureRecognizer.view row:row column:column];
-
- // TouchLabel* label = (TouchLabel*)gestureRecognizer.view;
- //
- //
- //
- //
- //
- // NSString * url =[self.hrefs valueForKey:label.text];
- // if(url!=nil)
- // {
- // label.textColor = [UIColor purpleColor];
- // [griddelegate Tap:label url:url];//first row is header;
- // }
-
- }
- -(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) to:destView.frame.size];
- UIButton* btn = [[UIButton alloc] initWithFrame:srect];
- [btn setTitle:template[@"title"] forState:UIControlStateNormal];
- [btn setTitleColor:UIColor.blackColor 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) 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;
-
- if(self.currentAppOrientation==ScreenOrientationLand)
- fontsize=fontsize*0.8; // 缩小字体否则textview显示不下。
- 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:(double)size x:(double)x y:(double)y destView:(UIView*)destView
- {
-
-
- CGRect srect=[self scaleControl:CGRectMake(x,y,size,size) from:CGSizeMake(768, 960) 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) 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.alpha=0.5;
- [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.page_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"] floatValue] x:[item[1][0] floatValue] y:[item[1][1] floatValue] 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) 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;
-
- }
- else
- {
- if([template[@"disable"] boolValue]&& [template[@"required"] boolValue])
- {
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- UIImage* img = [UIImage imageNamed:@"na"];
- btn.image = img;
- template[@"value"]=appDelegate.na_path;
-
- }
- }
-
- 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) 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 = UIColor.clearColor;//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;
- // DebugLog(@"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.pdfPageView setNeedsDisplay];
- }
- //- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
- //
- //
- //
- //}
- #pragma mark Button Click
- - (void)ControlDatePickerClicked:(UIButton *)sender {
-
-
- long index = sender.tag - CONTROL_BASE;
-
-
- if([self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"disable"] boolValue] )
- {
- return;
- }
-
- __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.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = strdate;
- weakSelf.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"dirty"]=[NSNumber numberWithBool:true];
- };
- dpvc.title=@"Please choose a date";
- [self.navigationController pushViewController:dpvc animated:true];
- }
- - (void)ControlButtonClicked:(UIButton *)sender {
- // DebugLog(@"cart sort button clicked");
-
- DebugLog(@"button clicked;");
-
- if([sender.titleLabel.text isEqualToString:@"Initial All"])
- {
-
- __weak __typeof(self)weakSelf = self;
-
-
-
- long index = sender.tag - CONTROL_BASE;
-
-
- NSMutableDictionary* control_json = self.page_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= sender.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.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
- // weakSelf.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"dirty"] = [NSNumber numberWithBool:true];
- // }
- //
- // };
- // 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= sender.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:@"Customer Initial"];
- // long index = sender.tag - CONTROL_BASE;
- // self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
- // self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"dirty"] =[NSNumber numberWithBool:true];
-
- if(weakSelf.blk_Fill)
- weakSelf.blk_Fill(file,@"Customer Initial",true);
-
- // 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];
- }
- // [self.view addSubview:self.sortItemController.view];
- }
- - (void)CheckButtonClicked:(UIButton *)sender {
- // DebugLog(@"cart sort button clicked");
-
- DebugLog(@"check clicked;");
-
- long index = sender.tag - CONTROL_BASE;
-
- bool single_select = [self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"single_select"] boolValue];
- bool show_detail = [self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"show_detail"] boolValue];
- NSArray* rowData = self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"cadedate"];
- NSArray* checkedData = self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"];
- CheckSelectorViewController *checkVC = [ [UIStoryboard storyboardWithName:@"Main" 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];
-
- // checkmarker 不显示,则显示选项内容文字。
- if(checkmarker.count==0)
- {
- sender.backgroundColor = UIColorFromRGB(CK_BG);
- if([checkedData containsObject:[NSNumber numberWithLong:i]])
- {
- [sender setTitle:item[0][0] forState:UIControlStateNormal];
- }
- // continue;
- }
- else
- {
- [sender setTitle:@"" forState:UIControlStateNormal];
- 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= UIColorFromRGB(CK_BG);//[UIColor clearColor];
- }
- }
-
- bool checked =[checkedData containsObject:[NSNumber numberWithLong:i]];
- if(item.count>=3) // 模板有action项
- {
- //[sender setTitle:item[0][0] forState:UIControlStateNormal];
- NSMutableDictionary* action = item[2];
- if(checked)
- {
- if([action[@"type"] isEqualToString:@"disable"] )
- {
- NSArray* disable_arr = action[@"disable"] ;
- for(int d = 0 ; d<disable_arr.count;d++)
- {
- self.page_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.page_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_10"];
- NSString* text = tv6.text;
- NSString* newvalue = nil;
- if([value isEqualToString:@"*0.1"])
- {
-
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
- formatter.numberStyle =NSNumberFormatterCurrencyStyle;
- NSString* prefix_str= self.page_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.page_controlTemplate [control[@"control"] ][@"value"] = newvalue;
- self.page_controlTemplate [control[@"control"] ][@"dirty"] = [NSNumber numberWithBool:true];
- }
- else if([value isEqualToString:@"*0.9"])
- {
- // float f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue]*0.9;
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
- formatter.numberStyle =NSNumberFormatterCurrencyStyle;
- NSString* prefix_str= self.page_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.page_controlTemplate [control[@"control"] ][@"value"] = newvalue;
- self.page_controlTemplate [control[@"control"] ][@"dirty"] = [NSNumber numberWithBool:true];
- }
-
-
- tv.text = newvalue;
-
- }
- NSMutableDictionary* json_cd=action[@"conditional_constraint"][checked?@"true":@"false"] ;
- {
- for(int i=0;i<[json_cd[@"count"] intValue];i++)
- {
-
- NSMutableDictionary * destination = json_cd [[NSString stringWithFormat:@"item_%d",i] ];
- int page = [destination[@"page"] intValue];
- NSString* control = destination[@"control"];
- self.doc_controlTemplate[[NSString stringWithFormat:@"page_%d",page]][control][@"disable"]=destination[@"disable"];
- id value =destination[@"set_val"];
- self.doc_controlTemplate[[NSString stringWithFormat:@"page_%d",page]][control][@"value"]=value;
- // UITextView* tv = (UITextView*) [self findControl:destination[@"control"]];
- // NSString* value = control[@"value"];
- //
- // UITextView* tv6 = (UITextView*) [self findControl:@"control_10"];
- // NSString* text = tv6.text;
- // NSString* newvalue = nil;
- // if([value isEqualToString:@"*0.1"])
- // {
- //
- // NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
- // formatter.numberStyle =kCFNumberFormatterCurrencyStyle;
- // NSString* prefix_str= self.page_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.page_controlTemplate [control[@"control"] ][@"value"] = newvalue;
- // self.page_controlTemplate [control[@"control"] ][@"dirty"] = [NSNumber numberWithBool:true];
- // }
- // 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.page_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.page_controlTemplate [control[@"control"] ][@"value"] = newvalue;
- // self.page_controlTemplate [control[@"control"] ][@"dirty"] = [NSNumber numberWithBool:true];
- // }
- //
- //
- // tv.text = newvalue;
-
- }
- }
- }
- else if([action[@"type"] isEqualToString:@"change contract"] )
- {
- NSString* pdf = action[@"contract"];
- if(self.chg_Contract)
- self.chg_Contract(pdf);
- }
-
- }
-
-
-
- }
-
- // UIView* v= sender;
-
-
- }
- self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"]=checkedData;
-
- self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"dirty"] = [NSNumber numberWithBool:true];
- };
- checkVC.rowData = rowData;
- checkVC.checkedData = [checkedData mutableCopy];
- checkVC.single_select = single_select;
- checkVC.show_detail = show_detail;
-
- checkVC.title=@"abcdefg";
- checkVC.modalPresentationStyle = UIModalPresentationFormSheet;
- [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];
-
- UITextView * tv = [self findNextTV:textView];
-
- if(tv)
- [tv becomeFirstResponder];
-
- [textView resignFirstResponder];
- return false;
- }
-
- NSString* tv_format=self.page_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.page_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.page_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.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"format"];
- if([tv_format isEqualToString:@"price"])
- {
-
- NSString* prefix_str= self.page_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 =NSNumberFormatterCurrencyStyle;
- 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
- {
-
- DebugLog(@"textViewShouldBeginEditing");
-
-
- // long index = textView.tag - CONTROL_BASE;
- //
- //
- // NSMutableDictionary* control_json = self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ];
- //
- // if([control_json[@"disable"] boolValue] )
- // {
- // return false;
- // }
- //
-
-
-
- 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.page_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.page_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.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"format"] isEqualToString:@"price"])
- {
- text =textView.text;
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
-
- formatter.numberStyle =NSNumberFormatterCurrencyStyle;
-
-
- 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.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = text;
- self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"dirty"] =[NSNumber numberWithBool:true];
- NSDictionary* action = self.page_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 =NSNumberFormatterCurrencyStyle;
-
- NSString* prefix_str= self.page_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.page_controlTemplate [control[@"control"] ][@"value"] = newvalue;
- self.page_controlTemplate [control[@"control"] ][@"dirty"] =[NSNumber numberWithBool:true];
- }
- else if([value isEqualToString:@"*0.9"])
- {
- // double f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] doubleValue]*0.9;
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
- formatter.numberStyle =NSNumberFormatterCurrencyStyle;
-
- NSString* prefix_str= self.page_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.page_controlTemplate [control[@"control"] ][@"value"] = newvalue;
- self.page_controlTemplate [control[@"control"] ][@"dirty"] = [NSNumber numberWithBool:true];
-
- }
- else if([value isEqualToString:@"control_6-control_7"])
- {
-
- UITextView* tv6 = (UITextView*) [self findControl:@"control_8"];
- // float f6= [[tv6.text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue];
- //
- // float f7= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue];
-
-
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
- formatter.numberStyle =NSNumberFormatterCurrencyStyle;
-
- NSString* prefix_str= self.page_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.page_controlTemplate [control[@"control"] ][@"value"] = newvalue;
- self.page_controlTemplate [control[@"control"] ][@"dirty"] = [NSNumber numberWithBool:true];
- tv.text = newvalue;
- }
- else if([value isEqualToString:@"copy"])
- {
- NSString* page = control[@"page"];
- NSString* controln = control[@"control"];
- NSString* source = control[@"source"];
- if([source isEqualToString:@"2+3+4+5"])
- {
- NSString* newval;
- NSString* s2=self.page_controlTemplate[@"control_2"][@"value"];
- NSString* s3=self.page_controlTemplate[@"control_3"][@"value"];
- NSString* s4=self.page_controlTemplate[@"control_4"][@"value"];
- NSString* s5=self.page_controlTemplate[@"control_5"][@"value"];
-
- if(s2==nil)
- s2=@"";
- if(s3==nil)
- s3=@"";
- if(s4==nil)
- s4=@"";
- if(s5==nil)
- s5=@"";
-
- newval=[NSString stringWithFormat:@"%@, %@, %@ %@",s2,s3,s4,s5];
- self.doc_controlTemplate[page][controln][@"value"]=newval;
- }
- else
- self.doc_controlTemplate[page][controln][@"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) signature:(TouchImageView *)touchImageView
- {
- __weak __typeof(self)weakSelf = self;
-
-
-
- long index = touchImageView.tag - CONTROL_BASE;
-
-
- NSMutableDictionary* control_json = self.page_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.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
- weakSelf.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"dirty"] = [NSNumber numberWithBool:true];
- }
-
- };
- 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.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
- self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"dirty"] =[NSNumber numberWithBool:true];
- 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];
- }
- - (void) TouchImageViewOnLongPress:(TouchImageView *)touchImageView
- {
-
- long index = touchImageView.tag - CONTROL_BASE;
-
-
- NSMutableDictionary* control_json = self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ];
-
- if([control_json[@"disable"] boolValue] )
- {
- return;
- }
-
- if(touchImageView.image!=nil)
- {
- DebugLog(@"long press");
-
-
- [self becomeFirstResponder];
- UIView* v = touchImageView;
-
- self.tiv_index = v.tag;
- UIMenuItem *clear = [[UIMenuItem alloc] initWithTitle:@"Clear" action:@selector(touchImageClear:)];
- // UIMenuItem *modify = [[UIMenuItem alloc] initWithTitle:@"Modify" action:@selector(touchImageModify:)];
- // [detail setValue:_id forKey:@"_id"];
-
- UIMenuController *menu = [UIMenuController sharedMenuController];
-
-
- [menu setMenuItems:[NSArray arrayWithObjects:clear,/*modify,*/ nil]];
-
- [menu setTargetRect:v.frame inView:v.superview];
- [menu setMenuVisible:YES animated:YES];
- }
- }
- //- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
- //{
- // if (action == @selector(showDetail:))
- // return YES;//显示
- // else
- // return NO;//不显示
- //}
- - (void) touchImageClear:(id) sender
- {
- long index = self.tiv_index - CONTROL_BASE;
-
- for(UIView*v in self.editControlView.subviews)
- {
- if(v.tag==self.tiv_index)
- ((UIImageView*)v).image = nil;
- }
- // NSMutableDictionary* control_json = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ];
-
- self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = @"";
- self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"dirty"] =[NSNumber numberWithBool:true];
- }
- - (void) touchImageModify:(id) sender
- {
-
- }
- - (void)TouchImageViewOnTouche:(TouchImageView *)touchImageView
- {
-
- DebugLog(@"signature button clicked;");
-
- //
- // __weak __typeof(self)weakSelf = self;
- //
- //
- //
- long index = touchImageView.tag - CONTROL_BASE;
-
-
- NSMutableDictionary* control_json = self.page_controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ];
- if([control_json[@"disable"] boolValue] )
- {
- return;
- }
-
-
- bool bvalidation=[control_json[@"required_validation"] boolValue];
- NSString* pwd= control_json[@"validation_code"];
- if(bvalidation&& pwd.length>0)
- {
-
-
- //UIAlertControllerStyle两种类型UIAlertControllerStyleAlert类似UIAlertView
- //UIAlertControllerStyleActionSheet类似UIActionSheet
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Authorization Verification" message:@"Please enter authorization code." preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
- [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
-
-
-
- }];
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- UITextField *name = alertControl.textFields.firstObject;
- if(![name.text isEqualToString:pwd])
- {
- // [RAUtils message_alert:@"You are not authorized to change this field" title:@"Authorization verification failed." controller:self];
-
- [RAUtils message_box:@"Authorization verification failed." message:@"You are not authorized to change this field" completion:nil];
- return;
- }
- else
- {
- [self signature:touchImageView];
- }
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- DebugLog(@"Cancel");
- return;
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
-
-
- }
- else
- {
- [self signature:touchImageView];
- }
- //// 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 {
- DebugLog(@"keyboardWillChangeFrame");
- }
- - (void)keyboardWillShow:(NSNotification *)notification {
- DebugLog(@"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;
- DebugLog(@"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;
- DebugLog(@"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 {
- DebugLog(@"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;
- // DebugLog(@"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
|