PageViewController.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. //
  2. // DocumentViewController.m
  3. // AntsContract
  4. //
  5. // Created by Ray on 12/16/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "PageViewController.h"
  9. #import "config.h"
  10. #import "const.h"
  11. #import "SignatureListViewController.h"
  12. #import "SignatureViewController.h"
  13. #import "PDFUtils.h"
  14. #import "ImageUtils.h"
  15. #import "CheckSelectorViewController.h"
  16. //#import "TouchImageView.h"
  17. @interface PageViewController ()
  18. @end
  19. @implementation PageViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // self.pageIndex=1;
  23. // self.pdfPageView.pageIndex=self.pageIndex;
  24. self.pdfPageView.pageRef= self.pageRef;
  25. [self initControl];
  26. // UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc]
  27. // initWithTarget:self
  28. // action:@selector(handlePinch:)];
  29. //
  30. // [self.view addGestureRecognizer:pinchGestureRecognizer];
  31. // Do any additional setup after loading the view.
  32. }
  33. -(void) dealloc
  34. {
  35. // CFBridgingRelease(self.pageRef);
  36. }
  37. - (void)didReceiveMemoryWarning {
  38. [super didReceiveMemoryWarning];
  39. // Dispose of any resources that can be recreated.
  40. }
  41. //- (void) handlePinch:(UIPinchGestureRecognizer*) recognizer
  42. //{
  43. //// recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
  44. //// recognizer.scale = 1;
  45. //
  46. // CGSize contentsize =self.pdfScrollView.contentSize;
  47. //
  48. // self.pdfScrollView.contentSize = CGSizeMake(contentsize.width*recognizer.scale, contentsize.height*recognizer.scale);
  49. //}
  50. -(void) initControl
  51. {
  52. int count = [self.controlTemplate[@"count"] intValue];
  53. for(int i=0;i<count;i++)
  54. {
  55. NSMutableDictionary * control =self.controlTemplate [[NSString stringWithFormat:@"control_%d",i] ];
  56. if([control[@"type"] isEqualToString:@"TextView"])
  57. {
  58. [self addTextView:control destView:self.editControlView index:i];
  59. }
  60. else if([control[@"type"] isEqualToString:@"Button"])
  61. {
  62. [self addButton:control destView:self.editControlView index:i];
  63. }
  64. else if([control[@"type"] isEqualToString:@"Check"])
  65. {
  66. [self addCheck:control destView:self.editControlView index:i];
  67. }
  68. else if([control[@"type"] isEqualToString:@"Signature"])
  69. {
  70. [self addSignatureButton:control destView:self.editControlView index:i];
  71. }
  72. else if([control[@"type"] isEqualToString:@"Image"])
  73. {
  74. [self addImage:control destView:self.editControlView index:i];
  75. }
  76. else if([control[@"type"] isEqualToString:@"Label"])
  77. {
  78. [self addLabel:control destView:self.editControlView index:i];
  79. }
  80. }
  81. }
  82. #pragma mark add controls
  83. -(void) addTextView:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  84. {
  85. UITextView* tv = [[UITextView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  86. float fontsize = [template[@"size"] floatValue];
  87. if(fontsize==0)
  88. fontsize=10;
  89. [tv setFont:[UIFont systemFontOfSize:fontsize]];
  90. tv.text =template[@"value"];
  91. tv.tag = index+ CONTROL_BASE;
  92. //UIColorFromARGB(0x4066ccff);
  93. tv.backgroundColor = UIColorFromRGB(TV_BG);//[UIColor lightGrayColor];
  94. // tv.place
  95. // [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  96. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  97. tv.delegate = self;
  98. // [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  99. if(DEBUG_PDFSIG)
  100. {
  101. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  102. }
  103. [destView addSubview:tv];
  104. }
  105. -(void) addLabel:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  106. {
  107. UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  108. float fontsize = [template[@"size"] floatValue];
  109. if(fontsize==0)
  110. fontsize=10;
  111. [label setFont:[UIFont systemFontOfSize:fontsize]];
  112. label.text =template[@"value"];
  113. label.tag = index+ CONTROL_BASE;
  114. //UIColorFromARGB(0x4066ccff);
  115. // tv.backgroundColor = UIColorFromRGB(TV_BG);//[UIColor lightGrayColor];
  116. // tv.place
  117. // [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  118. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  119. // tv.delegate = self;
  120. // [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  121. if(DEBUG_PDFSIG)
  122. {
  123. [label setBackgroundColor:[UIColor grayColor]];
  124. }
  125. [destView addSubview:label];
  126. }
  127. -(void) addButton:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  128. {
  129. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  130. [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  131. btn.tag = index+ CONTROL_BASE;
  132. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  133. btn.backgroundColor = UIColorFromRGB(BT_BG);
  134. [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  135. if(DEBUG_PDFSIG)
  136. {
  137. // btn.backgroundColor = [UIColor lightGrayColor];
  138. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  139. }
  140. [destView addSubview:btn];
  141. }
  142. -(UIView*) createMarker:(int)size x:(int)x y:(int)y
  143. {
  144. UIView* v=[[UIView alloc] initWithFrame:CGRectMake(x, y, size, size)];
  145. return v;
  146. }
  147. -(void) addCheck:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  148. {
  149. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  150. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  151. btn.tag = index+ CONTROL_BASE;
  152. [btn addTarget:self action:@selector(CheckButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  153. UIColor* marker_bg=UIColorFromRGB(CK_BG);//[UIColor clearColor];
  154. if(DEBUG_PDFSIG)
  155. {
  156. btn.backgroundColor = [UIColor lightGrayColor];
  157. [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  158. // marker_bg = [UIColor redColor];
  159. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  160. }
  161. [destView addSubview:btn];
  162. NSArray* cadedate = template[@"cadedate"];
  163. NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%d",index] ][@"value"];
  164. // if(checkedData.count>0)
  165. // marker_bg = [UIColor clearColor];
  166. // else
  167. marker_bg=UIColorFromRGB(CK_BG);
  168. for(int i=0;i<cadedate.count;i++)
  169. {
  170. NSArray* item = cadedate[i];
  171. UIView* marker=[self createMarker:[template[@"marker_size"] intValue] x:[item[1][0] intValue] y:[item[1][1] intValue]];
  172. marker.backgroundColor = marker_bg;
  173. marker.tag = CHECK_BASE+index*1000+i;
  174. if([checkedData containsObject:[NSNumber numberWithLong:i]])
  175. {
  176. marker.backgroundColor= UIColorFromRGB(CK_MK);
  177. }
  178. else
  179. {
  180. marker.backgroundColor= marker_bg;
  181. }
  182. [destView addSubview:marker];
  183. }
  184. }
  185. -(void) addSignatureButton:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  186. {
  187. TouchImageView* btn = [[TouchImageView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  188. btn.contentMode = UIViewContentModeScaleAspectFit;
  189. btn.delegate = self;
  190. btn.layer.borderColor = [UIColor clearColor].CGColor;
  191. btn.layer.borderWidth = 0;
  192. btn.tag = index+ CONTROL_BASE;
  193. NSString* file =template[@"value"];
  194. NSData* img_data=[ImageUtils load_img:file];
  195. if(img_data!=nil)
  196. {
  197. UIImage* image=[UIImage imageWithData:img_data];
  198. btn.image = image;
  199. }
  200. btn.backgroundColor = UIColorFromRGB(SIG_BG);
  201. if(DEBUG_PDFSIG)
  202. {
  203. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  204. }
  205. [destView addSubview:btn];
  206. }
  207. -(void) addImage:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  208. {
  209. UIImageView* btn = [[UIImageView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  210. btn.contentMode = UIViewContentModeScaleAspectFit;
  211. btn.layer.borderColor = [UIColor clearColor].CGColor;
  212. btn.layer.borderWidth = 0;
  213. btn.tag = index+ CONTROL_BASE;
  214. NSString* file =template[@"value"];
  215. NSData* img_data=[ImageUtils load_img:file];
  216. if(img_data!=nil)
  217. {
  218. UIImage* image=[UIImage imageWithData:img_data];
  219. btn.image = image;
  220. }
  221. btn.backgroundColor = UIColorFromRGB(SIG_BG);
  222. if(DEBUG_PDFSIG)
  223. {
  224. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  225. }
  226. [destView addSubview:btn];
  227. }
  228. #pragma mark UIScrollView delegate
  229. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
  230. UIView *subView = [scrollView viewWithTag:1024];
  231. return subView;
  232. }
  233. //- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
  234. //
  235. //
  236. //
  237. //}
  238. #pragma mark Button Click
  239. - (void)ControlButtonClicked:(UIButton *)sender {
  240. // DebugLog(@"cart sort button clicked");
  241. NSLog(@"button clicked;");
  242. // [self.view addSubview:self.sortItemController.view];
  243. }
  244. - (void)CheckButtonClicked:(UIButton *)sender {
  245. // DebugLog(@"cart sort button clicked");
  246. NSLog(@"check clicked;");
  247. long index = sender.tag - CONTROL_BASE;
  248. bool single_select = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"single_select"] boolValue];
  249. bool show_detail = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"show_detail"] boolValue];
  250. NSArray* rowData = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"cadedate"];
  251. NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"];
  252. CheckSelectorViewController *checkVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"CheckSelectorViewController"];
  253. checkVC.blk_OK = ^(NSArray* checkedData){
  254. for(int i=0;i<rowData.count;i++)
  255. {
  256. long tag=CHECK_BASE+index*1000+i;
  257. // UIView* v= sender;
  258. if([checkedData containsObject:[NSNumber numberWithLong:i]])
  259. {
  260. // [checkedData removeObject:[NSNumber numberWithLong:indexPath.row]];
  261. [sender.superview viewWithTag:tag].backgroundColor= [UIColor blackColor];
  262. }
  263. else
  264. {
  265. // [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
  266. [sender.superview viewWithTag:tag].backgroundColor= [UIColor clearColor];
  267. }
  268. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"]=checkedData;
  269. }
  270. };
  271. checkVC.rowData = rowData;
  272. checkVC.checkedData = [checkedData mutableCopy];
  273. checkVC.single_select = single_select;
  274. checkVC.show_detail = show_detail;
  275. checkVC.title=@"abcdefg";
  276. checkVC.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
  277. [self presentViewController:checkVC animated:YES completion:nil];
  278. }
  279. #pragma mark TextViewDelegate
  280. - (void)textViewDidEndEditing:(UITextView *)textView
  281. {
  282. long index = textView.tag - CONTROL_BASE;
  283. NSString* text =textView.text;
  284. if(text==nil)
  285. text=@"";
  286. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = text;
  287. // int count = [self.controlTemplate[@"count"] intValue];
  288. // for(int i=0;i<count;i++)
  289. // {
  290. // NSMutableDictionary * control =;
  291. //[self update_newprice];
  292. }
  293. /*
  294. #pragma mark - Navigation
  295. // In a storyboard-based application, you will often want to do a little preparation before navigation
  296. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  297. // Get the new view controller using [segue destinationViewController].
  298. // Pass the selected object to the new view controller.
  299. }
  300. */
  301. #pragma mark signature clicked
  302. //touchimageview Delegate
  303. - (void)TouchImageViewOnTouche:(TouchImageView *)touchImageView
  304. {
  305. NSLog(@"signature button clicked;");
  306. {
  307. // CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:trigger];
  308. //
  309. //
  310. // CGRect rect1=[self.view convertRect:cellrect_screen fromView:[[[UIApplication sharedApplication] delegate] window]];
  311. //
  312. // DebugLog(@"convert1 %@",NSStringFromCGRect(rect1));
  313. SignatureListViewController *signatureVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureListViewController"];
  314. signatureVC.title=@"Signatures";
  315. signatureVC.signatureData = self.signatureData;
  316. // signatureVC.imageView = touchImageView;
  317. signatureVC.blk_Select =^(NSString* file)
  318. {
  319. // NSString* file_name=[file lastPathComponent];
  320. NSData* img_data=[ImageUtils load_img:file];
  321. if(img_data!=nil)
  322. {
  323. UIImage* image=[UIImage imageWithData:img_data];
  324. touchImageView.image = image;
  325. long index = touchImageView.tag - CONTROL_BASE;
  326. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
  327. }
  328. };
  329. signatureVC.blk_Add = ^()
  330. {
  331. __block UIImage* signimg=nil;
  332. SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  333. vc.onReturnImg = ^(UIImage* img)
  334. {
  335. signimg = img;
  336. if(signimg!=nil)
  337. {
  338. NSString* file=[PDFUtils addSignature:signimg to:self.signatureData];
  339. long index = touchImageView.tag - CONTROL_BASE;
  340. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
  341. touchImageView.image = signimg;
  342. }
  343. };
  344. // orderinfoVC.url_type = URL_REMOTE;
  345. // orderinfoVC.request_url=URL_CARTDELIVERY;
  346. //
  347. // orderinfoVC.params = params;
  348. //
  349. // orderinfoVC.delegate=self;
  350. //
  351. // if(checked.count==count)
  352. // {
  353. // orderinfoVC.have_tail = true
  354. // }
  355. [self.navigationController pushViewController:vc animated:true];
  356. };
  357. UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:signatureVC];
  358. navi.modalPresentationStyle=UIModalPresentationPopover;
  359. UIPopoverPresentationController* popPc = navi.popoverPresentationController;
  360. popPc.permittedArrowDirections = UIPopoverArrowDirectionAny;
  361. popPc.sourceView = touchImageView;
  362. popPc.delegate = nil;
  363. [self presentViewController:navi animated:true completion:nil];
  364. //// menu.selector = self.selector;
  365. ////
  366. //// menu.selectordelegate = self;
  367. //
  368. // // 1.创建一个UIPopover
  369. // UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]];
  370. //
  371. //
  372. //
  373. // UIPopoverPresentationController
  374. // // 2.设置尺寸
  375. // // popover.popoverContentSize = CGSizeMake(320, 44 * 5);
  376. //
  377. // // 3.从哪里显示出来 --> 指向item
  378. //
  379. // [popover presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:0 animated:YES];
  380. // // [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  381. //
  382. //// self.popover = popover;
  383. // popover pop
  384. //
  385. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  386. }
  387. // __block int tag = touchImageView.tag;
  388. // UIViewController* vc=[RAUtils getViewController :touchImageView];
  389. //
  390. // if(self.editable==true)
  391. // {
  392. //
  393. //
  394. // ImageUploadViewController * uploadvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageUploadViewController"];
  395. //
  396. // // UIImage* img =[self.buttonImg backgroundImageForState:UIControlStateNormal];;
  397. //
  398. // if(self.img_validate)
  399. // uploadvc.img= touchImageView.image;
  400. //
  401. // uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
  402. // {
  403. //
  404. // self.imgs[tag] = url_up;
  405. //
  406. // NSString* newurl=[RAUtils arr2string:self.imgs separator:@"," trim:false];
  407. //
  408. // touchImageView.image=img;
  409. //
  410. // if(self.imgChanged)
  411. // self.imgChanged(url_down,newurl,tag,url_up);
  412. //
  413. // };
  414. //
  415. // [vc.navigationController pushViewController:uploadvc animated:false];
  416. // }
  417. // else
  418. // {
  419. // if(touchImageView.image==nil)
  420. // return ;
  421. // ImageViewController * imagevc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageViewController"];
  422. //
  423. //
  424. // UIImage* img=touchImageView.image;
  425. //
  426. // if(self.img_validate)
  427. // imagevc.image = img;//.imageView.image = [self.buttonImg backgroundImageForState:UIControlStateNormal];
  428. //
  429. // // uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
  430. // // {
  431. // //
  432. // // [self.buttonImg setBackgroundImage:img forState:UIControlStateNormal];
  433. // //
  434. // // if(self.imgChanged)
  435. // // self.imgChanged(url_down,url_up);
  436. // //
  437. // // };
  438. //
  439. // [vc.navigationController pushViewController:imagevc animated:false];
  440. // }
  441. // // bundleVC.content_data = self.bundle_item;
  442. //
  443. }
  444. @end