PageViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. }
  73. }
  74. #pragma mark add controls
  75. -(void) addTextView:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  76. {
  77. UITextView* tv = [[UITextView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  78. float fontsize = [template[@"size"] floatValue];
  79. if(fontsize==0)
  80. fontsize=10;
  81. [tv setFont:[UIFont systemFontOfSize:fontsize]];
  82. tv.text =template[@"value"];
  83. tv.tag = index+ CONTROL_BASE;
  84. //UIColorFromARGB(0x4066ccff);
  85. tv.backgroundColor = UIColorFromRGB(TV_BG);//[UIColor lightGrayColor];
  86. // tv.place
  87. // [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  88. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  89. tv.delegate = self;
  90. // [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  91. if(DEBUG_PDFSIG)
  92. {
  93. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  94. }
  95. [destView addSubview:tv];
  96. }
  97. -(void) addButton:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  98. {
  99. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  100. [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  101. btn.tag = index+ CONTROL_BASE;
  102. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  103. [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  104. if(DEBUG_PDFSIG)
  105. {
  106. btn.backgroundColor = [UIColor lightGrayColor];
  107. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  108. }
  109. [destView addSubview:btn];
  110. }
  111. -(UIView*) createMarker:(int)size x:(int)x y:(int)y
  112. {
  113. UIView* v=[[UIView alloc] initWithFrame:CGRectMake(x, y, size, size)];
  114. return v;
  115. }
  116. -(void) addCheck:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  117. {
  118. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  119. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  120. btn.tag = index+ CONTROL_BASE;
  121. [btn addTarget:self action:@selector(CheckButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  122. UIColor* marker_bg=UIColorFromRGB(CK_BG);//[UIColor clearColor];
  123. if(DEBUG_PDFSIG)
  124. {
  125. // btn.backgroundColor = [UIColor lightGrayColor];
  126. [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  127. // marker_bg = [UIColor redColor];
  128. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  129. }
  130. [destView addSubview:btn];
  131. NSArray* cadedate = template[@"cadedate"];
  132. NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%d",index] ][@"value"];
  133. // if(checkedData.count>0)
  134. // marker_bg = [UIColor clearColor];
  135. // else
  136. marker_bg=UIColorFromRGB(CK_BG);
  137. for(int i=0;i<cadedate.count;i++)
  138. {
  139. NSArray* item = cadedate[i];
  140. UIView* marker=[self createMarker:[template[@"marker_size"] intValue] x:[item[1][0] intValue] y:[item[1][1] intValue]];
  141. marker.backgroundColor = marker_bg;
  142. marker.tag = CHECK_BASE+index*1000+i;
  143. if([checkedData containsObject:[NSNumber numberWithLong:i]])
  144. {
  145. marker.backgroundColor= UIColorFromRGB(CK_MK);
  146. }
  147. else
  148. {
  149. marker.backgroundColor= marker_bg;
  150. }
  151. [destView addSubview:marker];
  152. }
  153. }
  154. -(void) addSignatureButton:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  155. {
  156. TouchImageView* btn = [[TouchImageView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  157. btn.contentMode = UIViewContentModeScaleAspectFit;
  158. btn.delegate = self;
  159. btn.layer.borderColor = [UIColor clearColor].CGColor;
  160. btn.layer.borderWidth = 0;
  161. btn.tag = index+ CONTROL_BASE;
  162. NSString* file =template[@"value"];
  163. NSData* img_data=[ImageUtils load_img:file];
  164. if(img_data!=nil)
  165. {
  166. UIImage* image=[UIImage imageWithData:img_data];
  167. btn.image = image;
  168. }
  169. btn.backgroundColor = UIColorFromRGB(SIG_BG);
  170. if(DEBUG_PDFSIG)
  171. {
  172. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  173. }
  174. [destView addSubview:btn];
  175. }
  176. #pragma mark UIScrollView delegate
  177. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
  178. UIView *subView = [scrollView viewWithTag:1024];
  179. return subView;
  180. }
  181. //- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
  182. //
  183. //
  184. //
  185. //}
  186. #pragma mark Button Click
  187. - (void)ControlButtonClicked:(UIButton *)sender {
  188. // DebugLog(@"cart sort button clicked");
  189. NSLog(@"button clicked;");
  190. // [self.view addSubview:self.sortItemController.view];
  191. }
  192. - (void)CheckButtonClicked:(UIButton *)sender {
  193. // DebugLog(@"cart sort button clicked");
  194. NSLog(@"check clicked;");
  195. long index = sender.tag - CONTROL_BASE;
  196. bool single_select = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"single_select"] boolValue];
  197. bool show_detail = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"show_detail"] boolValue];
  198. NSArray* rowData = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"cadedate"];
  199. NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"];
  200. CheckSelectorViewController *checkVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"CheckSelectorViewController"];
  201. checkVC.blk_OK = ^(NSArray* checkedData){
  202. for(int i=0;i<rowData.count;i++)
  203. {
  204. long tag=CHECK_BASE+index*1000+i;
  205. // UIView* v= sender;
  206. if([checkedData containsObject:[NSNumber numberWithLong:i]])
  207. {
  208. // [checkedData removeObject:[NSNumber numberWithLong:indexPath.row]];
  209. [sender.superview viewWithTag:tag].backgroundColor= [UIColor blackColor];
  210. }
  211. else
  212. {
  213. // [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
  214. [sender.superview viewWithTag:tag].backgroundColor= [UIColor clearColor];
  215. }
  216. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"]=checkedData;
  217. }
  218. };
  219. checkVC.rowData = rowData;
  220. checkVC.checkedData = [checkedData mutableCopy];
  221. checkVC.single_select = single_select;
  222. checkVC.show_detail = show_detail;
  223. checkVC.title=@"abcdefg";
  224. checkVC.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
  225. [self presentViewController:checkVC animated:YES completion:nil];
  226. }
  227. #pragma mark TextViewDelegate
  228. - (void)textViewDidEndEditing:(UITextView *)textView
  229. {
  230. long index = textView.tag - CONTROL_BASE;
  231. NSString* text =textView.text;
  232. if(text==nil)
  233. text=@"";
  234. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = text;
  235. // int count = [self.controlTemplate[@"count"] intValue];
  236. // for(int i=0;i<count;i++)
  237. // {
  238. // NSMutableDictionary * control =;
  239. //[self update_newprice];
  240. }
  241. /*
  242. #pragma mark - Navigation
  243. // In a storyboard-based application, you will often want to do a little preparation before navigation
  244. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  245. // Get the new view controller using [segue destinationViewController].
  246. // Pass the selected object to the new view controller.
  247. }
  248. */
  249. #pragma mark signature clicked
  250. //touchimageview Delegate
  251. - (void)TouchImageViewOnTouche:(TouchImageView *)touchImageView
  252. {
  253. NSLog(@"signature button clicked;");
  254. {
  255. // CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:trigger];
  256. //
  257. //
  258. // CGRect rect1=[self.view convertRect:cellrect_screen fromView:[[[UIApplication sharedApplication] delegate] window]];
  259. //
  260. // DebugLog(@"convert1 %@",NSStringFromCGRect(rect1));
  261. SignatureListViewController *signatureVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureListViewController"];
  262. signatureVC.title=@"Signatures";
  263. signatureVC.signatureData = self.signatureData;
  264. // signatureVC.imageView = touchImageView;
  265. signatureVC.blk_Select =^(NSString* file)
  266. {
  267. // NSString* file_name=[file lastPathComponent];
  268. NSData* img_data=[ImageUtils load_img:file];
  269. if(img_data!=nil)
  270. {
  271. UIImage* image=[UIImage imageWithData:img_data];
  272. touchImageView.image = image;
  273. long index = touchImageView.tag - CONTROL_BASE;
  274. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
  275. }
  276. };
  277. signatureVC.blk_Add = ^()
  278. {
  279. __block UIImage* signimg=nil;
  280. SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  281. vc.onReturnImg = ^(UIImage* img)
  282. {
  283. signimg = img;
  284. if(signimg!=nil)
  285. {
  286. NSString* file=[PDFUtils addSignature:signimg to:self.signatureData];
  287. long index = touchImageView.tag - CONTROL_BASE;
  288. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
  289. touchImageView.image = signimg;
  290. }
  291. };
  292. // orderinfoVC.url_type = URL_REMOTE;
  293. // orderinfoVC.request_url=URL_CARTDELIVERY;
  294. //
  295. // orderinfoVC.params = params;
  296. //
  297. // orderinfoVC.delegate=self;
  298. //
  299. // if(checked.count==count)
  300. // {
  301. // orderinfoVC.have_tail = true
  302. // }
  303. [self.navigationController pushViewController:vc animated:true];
  304. };
  305. UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:signatureVC];
  306. navi.modalPresentationStyle=UIModalPresentationPopover;
  307. UIPopoverPresentationController* popPc = navi.popoverPresentationController;
  308. popPc.permittedArrowDirections = UIPopoverArrowDirectionAny;
  309. popPc.sourceView = touchImageView;
  310. popPc.delegate = nil;
  311. [self presentViewController:navi animated:true completion:nil];
  312. //// menu.selector = self.selector;
  313. ////
  314. //// menu.selectordelegate = self;
  315. //
  316. // // 1.创建一个UIPopover
  317. // UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]];
  318. //
  319. //
  320. //
  321. // UIPopoverPresentationController
  322. // // 2.设置尺寸
  323. // // popover.popoverContentSize = CGSizeMake(320, 44 * 5);
  324. //
  325. // // 3.从哪里显示出来 --> 指向item
  326. //
  327. // [popover presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:0 animated:YES];
  328. // // [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  329. //
  330. //// self.popover = popover;
  331. // popover pop
  332. //
  333. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  334. }
  335. // __block int tag = touchImageView.tag;
  336. // UIViewController* vc=[RAUtils getViewController :touchImageView];
  337. //
  338. // if(self.editable==true)
  339. // {
  340. //
  341. //
  342. // ImageUploadViewController * uploadvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageUploadViewController"];
  343. //
  344. // // UIImage* img =[self.buttonImg backgroundImageForState:UIControlStateNormal];;
  345. //
  346. // if(self.img_validate)
  347. // uploadvc.img= touchImageView.image;
  348. //
  349. // uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
  350. // {
  351. //
  352. // self.imgs[tag] = url_up;
  353. //
  354. // NSString* newurl=[RAUtils arr2string:self.imgs separator:@"," trim:false];
  355. //
  356. // touchImageView.image=img;
  357. //
  358. // if(self.imgChanged)
  359. // self.imgChanged(url_down,newurl,tag,url_up);
  360. //
  361. // };
  362. //
  363. // [vc.navigationController pushViewController:uploadvc animated:false];
  364. // }
  365. // else
  366. // {
  367. // if(touchImageView.image==nil)
  368. // return ;
  369. // ImageViewController * imagevc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageViewController"];
  370. //
  371. //
  372. // UIImage* img=touchImageView.image;
  373. //
  374. // if(self.img_validate)
  375. // imagevc.image = img;//.imageView.image = [self.buttonImg backgroundImageForState:UIControlStateNormal];
  376. //
  377. // // uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
  378. // // {
  379. // //
  380. // // [self.buttonImg setBackgroundImage:img forState:UIControlStateNormal];
  381. // //
  382. // // if(self.imgChanged)
  383. // // self.imgChanged(url_down,url_up);
  384. // //
  385. // // };
  386. //
  387. // [vc.navigationController pushViewController:imagevc animated:false];
  388. // }
  389. // // bundleVC.content_data = self.bundle_item;
  390. //
  391. }
  392. @end