PageViewController.m 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  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 "TextUtils.h"
  16. #import "CheckSelectorViewController.h"
  17. #import "DatePickerViewController.h"
  18. //#import "TouchImageView.h"
  19. @interface PageViewController ()
  20. @end
  21. @implementation PageViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. //
  25. // self.pdfScrollView = [[PDFScrollView alloc]initWithFrame:CGRectMake(0, 64, 768, 960)];
  26. // self.pdfScrollView.backgroundColor= [UIColor redColor];
  27. //self.edgesForExtendedLayout = UIRectEdgeNone;
  28. // self.pageIndex=1;
  29. // self.pdfPageView.pageIndex=self.pageIndex;
  30. self.pdfPageView.pageRef= self.pageRef;
  31. self.pdfScrollView.contentSize = self.pdfScrollView.frame.size;
  32. self.keyboard_h=0;
  33. [self initControl];
  34. // UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc]
  35. // initWithTarget:self
  36. // action:@selector(handlePinch:)];
  37. //
  38. // [self.view addGestureRecognizer:pinchGestureRecognizer];
  39. // Do any additional setup after loading the view.
  40. }
  41. -(void)viewWillAppear:(BOOL)animated
  42. {
  43. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  44. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  45. // 键盘高度变化通知,ios5.0新增的
  46. #ifdef __IPHONE_5_0
  47. float version = [[[UIDevice currentDevice] systemVersion] floatValue];
  48. if (version >= 5.0) {
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
  50. }
  51. #endif
  52. // self.pdfScrollView.contentSize = self.pdfScrollView.frame.size;
  53. [self refreshControl];
  54. }
  55. -(void) viewWillDisappear:(BOOL)animated
  56. {
  57. [self.hotTextView endEditing:true];
  58. [[NSNotificationCenter defaultCenter] removeObserver:self];
  59. }
  60. -(void) dealloc
  61. {
  62. // CFBridgingRelease(self.pageRef);
  63. }
  64. - (void)didReceiveMemoryWarning {
  65. [super didReceiveMemoryWarning];
  66. // Dispose of any resources that can be recreated.
  67. }
  68. //- (void) handlePinch:(UIPinchGestureRecognizer*) recognizer
  69. //{
  70. //// recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
  71. //// recognizer.scale = 1;
  72. //
  73. // CGSize contentsize =self.pdfScrollView.contentSize;
  74. //
  75. // self.pdfScrollView.contentSize = CGSizeMake(contentsize.width*recognizer.scale, contentsize.height*recognizer.scale);
  76. //}
  77. -(void) initControl
  78. {
  79. int count = [self.controlTemplate[@"count"] intValue];
  80. for(int i=0;i<count;i++)
  81. {
  82. NSMutableDictionary * control =self.controlTemplate [[NSString stringWithFormat:@"control_%d",i] ];
  83. if([control[@"type"] isEqualToString:@"TextView"])
  84. {
  85. [self addTextView:control destView:self.editControlView index:i];
  86. }
  87. else if([control[@"type"] isEqualToString:@"Button"])
  88. {
  89. [self addButton:control destView:self.editControlView index:i];
  90. }
  91. else if([control[@"type"] isEqualToString:@"Check"])
  92. {
  93. [self addCheck:control destView:self.editControlView index:i];
  94. }
  95. else if([control[@"type"] isEqualToString:@"Signature"])
  96. {
  97. [self addSignatureButton:control destView:self.editControlView index:i];
  98. }
  99. else if([control[@"type"] isEqualToString:@"Image"])
  100. {
  101. [self addImage:control destView:self.editControlView index:i];
  102. }
  103. else if([control[@"type"] isEqualToString:@"Label"])
  104. {
  105. [self addLabel:control destView:self.editControlView index:i];
  106. }
  107. else if([control[@"type"] isEqualToString:@"DatePicker"])
  108. {
  109. [self addDatePicker:control destView:self.editControlView index:i];
  110. }
  111. }
  112. }
  113. -(void) refreshControl
  114. {
  115. int count = [self.controlTemplate[@"count"] intValue];
  116. for(int i=0;i<count;i++)
  117. {
  118. NSString* controlname =[NSString stringWithFormat:@"control_%d",i];
  119. NSMutableDictionary * control =self.controlTemplate [ controlname];
  120. // if([control[@"type"] isEqualToString:@"TextView"])
  121. // {
  122. // UITextView* tv = (UITextView*) [self findControl:controlname];
  123. // tv.text = control[@"value"];
  124. // }
  125. // else if([control[@"type"] isEqualToString:@"Button"])
  126. // {
  127. // [self addButton:control destView:self.editControlView index:i];
  128. //
  129. // }
  130. // else if([control[@"type"] isEqualToString:@"Check"])
  131. // {
  132. // [self addCheck:control destView:self.editControlView index:i];
  133. //
  134. // }
  135. // else
  136. if([control[@"type"] isEqualToString:@"Signature"])
  137. {
  138. TouchImageView* btn = (TouchImageView*) [self findControl:controlname];
  139. NSString* file =control[@"value"];
  140. NSData* img_data=[ImageUtils load_img:file];
  141. if(img_data!=nil)
  142. {
  143. UIImage* image=[UIImage imageWithData:img_data];
  144. btn.image = image;
  145. }
  146. }
  147. // else if([control[@"type"] isEqualToString:@"Image"])
  148. // {
  149. // [self addImage:control destView:self.editControlView index:i];
  150. //
  151. // }
  152. // else if([control[@"type"] isEqualToString:@"Label"])
  153. // {
  154. // [self addLabel:control destView:self.editControlView index:i];
  155. //
  156. // }
  157. // else if([control[@"type"] isEqualToString:@"DatePicker"])
  158. // {
  159. // [self addDatePicker:control destView:self.editControlView index:i];
  160. //
  161. // }
  162. }
  163. }
  164. -(void)EndEditing
  165. {
  166. [[self view] endEditing:YES];
  167. }
  168. #pragma mark add controls
  169. -(bool) checkActionCondition:(NSString*) condition
  170. {
  171. if([condition isEqualToString:@"true"])
  172. return true;
  173. if([condition isEqualToString:@"control_18:[value]==0"])
  174. {
  175. NSArray* arr= self.controlTemplate[@"control_18"][@"value"];
  176. if(arr.count==0)
  177. return false;
  178. else
  179. return [arr[0] intValue]==0;
  180. }
  181. return false;
  182. }
  183. -(UIView*) findControl:(NSString*)controlName
  184. {
  185. controlName=[controlName stringByReplacingOccurrencesOfString:@"control_" withString:@""];
  186. int d_idx = [controlName intValue];
  187. return [self.view viewWithTag:d_idx+CONTROL_BASE];
  188. }
  189. -(void) addTextView:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  190. {
  191. UITextView* tv = [[UITextView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  192. float fontsize = [template[@"size"] floatValue];
  193. if(fontsize==0)
  194. fontsize=10;
  195. [tv setFont:[UIFont systemFontOfSize:fontsize]];
  196. bool isdisable = [template[@"disable"] boolValue];
  197. tv.editable = !isdisable;
  198. NSString* text= template[@"value"];
  199. if(text.length==0)
  200. text=@" ";
  201. tv.text =text;
  202. float tv_vmargin= [template[@"tv_vmargin"] floatValue];
  203. NSString* capital= template[@"capital"];
  204. UITextAutocapitalizationType capitalType=UITextAutocapitalizationTypeWords;
  205. if([capital isEqualToString:@"charater"])
  206. {
  207. capitalType=UITextAutocapitalizationTypeAllCharacters;
  208. }
  209. else if([capital isEqualToString:@"sentences"])
  210. {
  211. capitalType=UITextAutocapitalizationTypeSentences;
  212. }
  213. else if([capital isEqualToString:@"none"])
  214. {
  215. capitalType=UITextAutocapitalizationTypeNone;
  216. }
  217. else
  218. {
  219. capitalType=UITextAutocapitalizationTypeWords;
  220. }
  221. tv.autocapitalizationType=capitalType;
  222. NSMutableAttributedString* attr_str= [tv.attributedText mutableCopy];
  223. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
  224. if(tv_vmargin!=0)
  225. paragraphStyle.lineHeightMultiple = tv_vmargin;
  226. // paragraphStyle.maximumLineHeight = 25.f;
  227. // paragraphStyle.minimumLineHeight = 15.f;
  228. // paragraphStyle.firstLineHeadIndent = 20.f;
  229. // paragraphStyle.alignment = NSTextAlignmentJustified;
  230. [attr_str addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,attr_str.length)];
  231. tv.attributedText=attr_str;
  232. if([text isEqualToString:(@" ")])
  233. tv.text=@"";
  234. tv.tag = index+ CONTROL_BASE;
  235. tv.scrollEnabled=false;
  236. //UIColorFromARGB(0x4066ccff);
  237. tv.backgroundColor = UIColorFromRGB(TV_BG);//[UIColor lightGrayColor];
  238. // tv.place
  239. // [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  240. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  241. tv.delegate = self;
  242. // [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  243. if(DEBUG_PDFSIG)
  244. {
  245. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  246. }
  247. [destView addSubview:tv];
  248. }
  249. -(void) addLabel:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  250. {
  251. UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  252. float fontsize = [template[@"size"] floatValue];
  253. if(fontsize==0)
  254. fontsize=10;
  255. [label setFont:[UIFont systemFontOfSize:fontsize]];
  256. label.text =template[@"value"];
  257. label.tag = index+ CONTROL_BASE;
  258. //UIColorFromARGB(0x4066ccff);
  259. // tv.backgroundColor = UIColorFromRGB(TV_BG);//[UIColor lightGrayColor];
  260. // tv.place
  261. // [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  262. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  263. // tv.delegate = self;
  264. // [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  265. if(DEBUG_PDFSIG)
  266. {
  267. [label setBackgroundColor:[UIColor grayColor]];
  268. }
  269. [destView addSubview:label];
  270. }
  271. -(void) addButton:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  272. {
  273. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  274. [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  275. btn.tag = index+ CONTROL_BASE;
  276. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  277. btn.backgroundColor = UIColorFromRGB(BT_BG);
  278. [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  279. if(DEBUG_PDFSIG)
  280. {
  281. // btn.backgroundColor = [UIColor lightGrayColor];
  282. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  283. }
  284. [destView addSubview:btn];
  285. }
  286. -(void) addDatePicker:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  287. {
  288. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  289. [btn setTitle:template[@"value"] forState:UIControlStateNormal];
  290. float fontsize = [template[@"size"] floatValue];
  291. if(fontsize==0)
  292. fontsize=10;
  293. btn.titleLabel.font = [UIFont systemFontOfSize: fontsize];
  294. btn.tag = index+ CONTROL_BASE;
  295. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  296. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  297. btn.backgroundColor = UIColorFromRGB(BT_BG);
  298. [btn addTarget:self action:@selector(ControlDatePickerClicked:) forControlEvents:UIControlEventTouchUpInside];
  299. if(DEBUG_PDFSIG)
  300. {
  301. // btn.backgroundColor = [UIColor lightGrayColor];
  302. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  303. }
  304. [destView addSubview:btn];
  305. }
  306. -(UIView*) createMarker:(int)size x:(int)x y:(int)y
  307. {
  308. UIView* v=[[UIView alloc] initWithFrame:CGRectMake(x, y, size, size)];
  309. return v;
  310. }
  311. -(void) addCheck:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  312. {
  313. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  314. // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
  315. btn.tag = index+ CONTROL_BASE;
  316. [btn addTarget:self action:@selector(CheckButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  317. UIColor* marker_bg=UIColorFromRGB(CK_BG);//[UIColor clearColor];
  318. if(DEBUG_PDFSIG)
  319. {
  320. btn.backgroundColor = [UIColor lightGrayColor];
  321. [btn setTitle:template[@"title"] forState:UIControlStateNormal];
  322. // marker_bg = [UIColor redColor];
  323. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  324. }
  325. [destView addSubview:btn];
  326. NSArray* cadedate = template[@"cadedate"];
  327. NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%d",index] ][@"value"];
  328. float fontsize = [template[@"size"] floatValue];
  329. if(fontsize==0)
  330. fontsize=10;
  331. // if(checkedData.count>0)
  332. // marker_bg = [UIColor clearColor];
  333. // else
  334. marker_bg=UIColorFromRGB(CK_BG);
  335. for(int i=0;i<cadedate.count;i++)
  336. {
  337. NSArray* item = cadedate[i];
  338. NSArray* checkmarker = item[1];
  339. if(checkmarker.count==0)
  340. {
  341. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  342. btn.titleLabel.font = [UIFont systemFontOfSize: fontsize];
  343. btn.backgroundColor = UIColorFromRGB(CK_BG);
  344. if([checkedData containsObject:[NSNumber numberWithLong:i]])
  345. {
  346. [btn setTitle:item[0][0] forState:UIControlStateNormal];
  347. }
  348. continue;
  349. }
  350. else
  351. {
  352. [btn setTitle:@"" forState:UIControlStateNormal];
  353. }
  354. UIView* marker=[self createMarker:[template[@"marker_size"] intValue] x:[item[1][0] intValue] y:[item[1][1] intValue]];
  355. marker.backgroundColor = marker_bg;
  356. marker.tag = CHECK_BASE+index*1000+i;
  357. if([checkedData containsObject:[NSNumber numberWithLong:i]])
  358. {
  359. marker.backgroundColor= UIColorFromRGB(CK_MK);
  360. }
  361. else
  362. {
  363. marker.backgroundColor= marker_bg;
  364. }
  365. [destView addSubview:marker];
  366. }
  367. }
  368. -(void) addSignatureButton:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  369. {
  370. TouchImageView* btn = [[TouchImageView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  371. btn.contentMode = UIViewContentModeScaleAspectFit;
  372. btn.delegate = self;
  373. btn.layer.borderColor = [UIColor clearColor].CGColor;
  374. btn.layer.borderWidth = 0;
  375. btn.tag = index+ CONTROL_BASE;
  376. NSString* file =template[@"value"];
  377. NSData* img_data=[ImageUtils load_img:file];
  378. if(img_data!=nil)
  379. {
  380. UIImage* image=[UIImage imageWithData:img_data];
  381. btn.image = image;
  382. }
  383. btn.backgroundColor = UIColorFromRGB(SIG_BG);
  384. if(DEBUG_PDFSIG)
  385. {
  386. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  387. }
  388. [destView addSubview:btn];
  389. }
  390. -(void) addImage:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
  391. {
  392. UIImageView* btn = [[UIImageView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
  393. btn.contentMode = UIViewContentModeScaleAspectFit;
  394. btn.layer.borderColor = [UIColor clearColor].CGColor;
  395. btn.layer.borderWidth = 0;
  396. btn.tag = index+ CONTROL_BASE;
  397. NSString* file =template[@"value"];
  398. NSData* img_data=[ImageUtils load_img:file];
  399. if(img_data!=nil)
  400. {
  401. UIImage* image=[UIImage imageWithData:img_data];
  402. btn.image = image;
  403. }
  404. btn.backgroundColor = UIColorFromRGB(SIG_BG);
  405. if(DEBUG_PDFSIG)
  406. {
  407. // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
  408. }
  409. [destView addSubview:btn];
  410. }
  411. #pragma mark UIScrollView delegate
  412. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
  413. UIView *subView = [scrollView viewWithTag:1024];
  414. return subView;
  415. }
  416. - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale
  417. {
  418. CGPoint contentOffsetPoint = self.pdfScrollView.contentOffset;
  419. CGSize contentSize =self.pdfScrollView.contentSize;//frame.size;
  420. // CGSize size1 = self.pdfScrollView.bounds.size;
  421. // NSLog(@"frame:%@ bound:%@", NSStringFromCGSize(contentSize),NSStringFromCGSize(size1) );
  422. contentSize.height+=self.keyboard_h;
  423. contentOffsetPoint.y+=self.keyboard_h;
  424. self.pdfScrollView.contentSize =contentSize;
  425. self.pdfScrollView.contentOffset=contentOffsetPoint;
  426. }
  427. //- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
  428. //
  429. //
  430. //
  431. //}
  432. #pragma mark Button Click
  433. - (void)ControlDatePickerClicked:(UIButton *)sender {
  434. long index = sender.tag - CONTROL_BASE;
  435. __weak __typeof(self)weakSelf = self;
  436. NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
  437. [formatter setDateFormat:@"MM/dd/yyyy"];
  438. NSString* date = sender.currentTitle;
  439. NSDate* currentDate =nil;
  440. if(date.length==0)
  441. currentDate=[NSDate date];
  442. else
  443. currentDate=[formatter dateFromString:date];
  444. DatePickerViewController* dpvc =[ [UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"DatePickerViewController"];
  445. dpvc.pickerMode = UIDatePickerModeDate;
  446. dpvc.date = currentDate;
  447. dpvc.formatter = formatter;
  448. dpvc.labelTime.text = [formatter stringFromDate:currentDate];
  449. dpvc.blk_Set = ^(NSString* strdate)
  450. {
  451. // weakSelf.labelSignDate.text = strdate;
  452. [sender setTitle:strdate forState:UIControlStateNormal];
  453. weakSelf.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = strdate;
  454. };
  455. dpvc.title=@"Please choose a date";
  456. [self.navigationController pushViewController:dpvc animated:true];
  457. }
  458. - (void)ControlButtonClicked:(UIButton *)sender {
  459. // DebugLog(@"cart sort button clicked");
  460. NSLog(@"button clicked;");
  461. // [self.view addSubview:self.sortItemController.view];
  462. }
  463. - (void)CheckButtonClicked:(UIButton *)sender {
  464. // DebugLog(@"cart sort button clicked");
  465. NSLog(@"check clicked;");
  466. long index = sender.tag - CONTROL_BASE;
  467. bool single_select = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"single_select"] boolValue];
  468. bool show_detail = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"show_detail"] boolValue];
  469. NSArray* rowData = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"cadedate"];
  470. NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"];
  471. CheckSelectorViewController *checkVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"CheckSelectorViewController"];
  472. checkVC.blk_OK = ^(NSArray* checkedData){
  473. for(int i=0;i<rowData.count;i++)
  474. {
  475. long tag=CHECK_BASE+index*1000+i;
  476. NSArray* item = rowData[i];
  477. NSArray* checkmarker = item[1];
  478. if(checkmarker.count==0)
  479. {
  480. sender.backgroundColor = UIColorFromRGB(CK_BG);
  481. if([checkedData containsObject:[NSNumber numberWithLong:i]])
  482. {
  483. [sender setTitle:item[0][0] forState:UIControlStateNormal];
  484. if(item.count>=3)
  485. {
  486. NSMutableDictionary* action = item[2];
  487. NSArray* disable_arr = action[@"disable"] ;
  488. for(int d = 0 ; d<disable_arr.count;d++)
  489. {
  490. self.controlTemplate [disable_arr[d] ] [@"disable"] = [NSNumber numberWithBool:true];
  491. NSString* s_idx =disable_arr[d];
  492. s_idx=[s_idx stringByReplacingOccurrencesOfString:@"control_" withString:@""];
  493. int d_idx = [s_idx intValue];
  494. ((UITextView*)[sender.superview viewWithTag:d_idx+CONTROL_BASE]).editable = false;
  495. }
  496. NSArray* enable_arr = action[@"enable"] ;
  497. for(int e = 0 ; e<enable_arr.count;e++)
  498. {
  499. self.controlTemplate [enable_arr[e] ] [@"disable"] = [NSNumber numberWithBool:false];
  500. NSString* s_idx =enable_arr[e];
  501. s_idx=[s_idx stringByReplacingOccurrencesOfString:@"control_" withString:@""];
  502. int d_idx = [s_idx intValue];
  503. ((UITextView*)[sender.superview viewWithTag:d_idx+CONTROL_BASE]).editable = true;
  504. }
  505. NSMutableDictionary* json_setval=action[@"set_val"] ;
  506. for(int i=0;i<[json_setval[@"count"] intValue];i++)
  507. {
  508. NSMutableDictionary * control = json_setval [[NSString stringWithFormat:@"item_%d",i] ];
  509. UITextView* tv = (UITextView*) [self findControl:control[@"control"]];
  510. NSString* value = control[@"value"];
  511. UITextView* tv6 = (UITextView*) [self findControl:@"control_6"];
  512. NSString* text = tv6.text;
  513. NSString* newvalue = nil;
  514. if([value isEqualToString:@"*0.1"])
  515. {
  516. float f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue]*0.1;
  517. newvalue = [NSString stringWithFormat:@"$ %.2f",f];
  518. self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
  519. }
  520. else if([value isEqualToString:@"*0.9"])
  521. {
  522. float f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue]*0.9;
  523. newvalue = [NSString stringWithFormat:@"$ %.2f",f];
  524. self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
  525. }
  526. tv.text = newvalue;
  527. }
  528. }
  529. }
  530. continue;
  531. }
  532. else
  533. {
  534. [sender setTitle:@"" forState:UIControlStateNormal];
  535. }
  536. // UIView* v= sender;
  537. if([checkedData containsObject:[NSNumber numberWithLong:i]])
  538. {
  539. // [checkedData removeObject:[NSNumber numberWithLong:indexPath.row]];
  540. [sender.superview viewWithTag:tag].backgroundColor= [UIColor blackColor];
  541. }
  542. else
  543. {
  544. // [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
  545. [sender.superview viewWithTag:tag].backgroundColor= [UIColor clearColor];
  546. }
  547. }
  548. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"]=checkedData;
  549. };
  550. checkVC.rowData = rowData;
  551. checkVC.checkedData = [checkedData mutableCopy];
  552. checkVC.single_select = single_select;
  553. checkVC.show_detail = show_detail;
  554. checkVC.title=@"abcdefg";
  555. checkVC.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
  556. [self presentViewController:checkVC animated:YES completion:nil];
  557. }
  558. #pragma mark TextViewDelegate
  559. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  560. {
  561. long index = textView.tag - CONTROL_BASE;
  562. if([text isEqualToString:@""])
  563. return true;
  564. if([text isEqualToString:@"\n"])
  565. {
  566. [textView resignFirstResponder];
  567. return false;
  568. }
  569. NSString* tv_format=self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"format"];
  570. if([tv_format isEqualToString:@"us_tel"])
  571. {
  572. NSMutableString *newString = [[textView.text stringByReplacingCharactersInRange:range withString:text] mutableCopy];
  573. NSArray *components = [newString componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
  574. NSString *decimalString = [components componentsJoinedByString:@""];
  575. NSUInteger length = decimalString.length;
  576. BOOL hasLeadingOne = length > 0 && [decimalString characterAtIndex:0] == '1';
  577. if (length == 0 ) {
  578. textView.text = decimalString;
  579. return NO;
  580. }
  581. if((length >= 10 && !hasLeadingOne) )
  582. {
  583. if(length>15)
  584. return NO;
  585. // newString=[[newString stringByReplacingOccurrencesOfString:@"-" withString:@""] mutableCopy];
  586. // [newString insertString:@"-" atIndex:14];
  587. // textView.text = newString;
  588. // return NO;
  589. }
  590. if((length >= 11))
  591. {
  592. if(length>16)
  593. return NO;
  594. // newString=[[newString stringByReplacingOccurrencesOfString:@"-" withString:@""] mutableCopy];
  595. // [newString insertString:@"-" atIndex:16];
  596. // textView.text = newString;
  597. // return NO;
  598. }
  599. NSUInteger index = 0;
  600. NSMutableString *formattedString = [NSMutableString string];
  601. if (hasLeadingOne) {
  602. [formattedString appendString:@"1 "];
  603. index += 1;
  604. }
  605. if (length - index > 3) {
  606. NSString *areaCode = [decimalString substringWithRange:NSMakeRange(index, 3)];
  607. [formattedString appendFormat:@"(%@) ",areaCode];
  608. index += 3;
  609. }
  610. if (length - index > 3) {
  611. NSString *prefix = [decimalString substringWithRange:NSMakeRange(index, 3)];
  612. [formattedString appendFormat:@"%@ ",prefix];
  613. index += 3;
  614. }
  615. if (length - index > 4) {
  616. NSString *prefix = [decimalString substringWithRange:NSMakeRange(index, 4)];
  617. [formattedString appendFormat:@"%@-",prefix];
  618. index += 4;
  619. }
  620. NSString *remainder = [decimalString substringFromIndex:index];
  621. [formattedString appendString:remainder];
  622. textView.text = formattedString;
  623. return NO;
  624. }
  625. else
  626. {
  627. NSString* oldtext =textView.text;
  628. if(oldtext==nil)
  629. oldtext=@"";
  630. bool canChange=true;
  631. int max_line = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"lines"] intValue];
  632. if(max_line==0)//默认只能有一行
  633. max_line=1;
  634. long linecount=[TextUtils countOccurencesOfString:oldtext find:@"\n"];
  635. if(max_line!=-1) //maxline -1表示不限制行数。
  636. {
  637. if(linecount<=max_line-1&& [text isEqualToString:@"\n"])
  638. {
  639. canChange = false;
  640. }
  641. }
  642. int lenth = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"length"] intValue];
  643. if(lenth==0)
  644. return canChange;
  645. else
  646. {
  647. return canChange&& (lenth>textView.text.length ||[text isEqualToString:@""]);
  648. }
  649. }
  650. }
  651. //- (void)textViewDidBeginEditing:(UITextView *)textView
  652. //{
  653. // self.hotTextView = textView;
  654. //}
  655. - (BOOL)textViewShouldBeginEditing:(UITextView *)textView
  656. {
  657. NSLog(@"textViewShouldBeginEditing");
  658. self.hotTextView = textView;//(UITableViewCell*)textView.superview.superview;
  659. return textView.editable;
  660. }
  661. - (void)textViewDidEndEditing:(UITextView *)textView
  662. {
  663. long index = textView.tag - CONTROL_BASE;
  664. //处理 prefix 和 浮点格式化
  665. NSString* prefix_str= self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"prefix_str"];
  666. if(prefix_str.length==0)
  667. prefix_str = @"";
  668. NSString* text = [textView.text stringByReplacingOccurrencesOfString:prefix_str withString:@""];
  669. NSString* value_type= self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value_type"];
  670. if([value_type isEqualToString:@"float"])
  671. text=[NSString stringWithFormat:@"%.2f",[text doubleValue] ];
  672. text =[NSString stringWithFormat:@"%@%@",prefix_str,text] ;
  673. textView.text = text;
  674. if(text==nil)
  675. text=@"";
  676. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = text;
  677. NSDictionary* action = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"action"];
  678. NSArray* keys=[action allKeys];
  679. for(int k=0;k<keys.count;k++)
  680. {
  681. NSMutableDictionary* act_k = action[keys[k] ];
  682. if (![self checkActionCondition:act_k[@"condition"]])
  683. continue;
  684. for(int i=0;i<[act_k[@"count"] intValue];i++)
  685. {
  686. NSMutableDictionary * control = act_k [[NSString stringWithFormat:@"item_%d",i] ];
  687. UITextView* tv = (UITextView*) [self findControl:control[@"control"]];
  688. NSString* value = control[@"value"];
  689. NSString* newvalue = nil;
  690. if([value isEqualToString:@"*0.1"])
  691. {
  692. double f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] doubleValue]*0.1;
  693. newvalue = [NSString stringWithFormat:@"$ %.2f",f];
  694. self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
  695. }
  696. else if([value isEqualToString:@"*0.9"])
  697. {
  698. double f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] doubleValue]*0.9;
  699. newvalue = [NSString stringWithFormat:@"$ %.2f",f];
  700. self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
  701. }
  702. else if([value isEqualToString:@"control_6-control_7"])
  703. {
  704. UITextView* tv6 = (UITextView*) [self findControl:@"control_6"];
  705. float f6= [[tv6.text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue];
  706. float f7= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue];
  707. newvalue = [NSString stringWithFormat:@"$ %.2f",f6-f7];
  708. self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
  709. }
  710. tv.text = newvalue;
  711. }
  712. }
  713. // int count = [self.controlTemplate[@"count"] intValue];
  714. // for(int i=0;i<count;i++)
  715. // {
  716. // NSMutableDictionary * control =;
  717. //[self update_newprice];
  718. }
  719. /*
  720. #pragma mark - Navigation
  721. // In a storyboard-based application, you will often want to do a little preparation before navigation
  722. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  723. // Get the new view controller using [segue destinationViewController].
  724. // Pass the selected object to the new view controller.
  725. }
  726. */
  727. #pragma mark signature clicked
  728. //touchimageview Delegate
  729. - (void)TouchImageViewOnTouche:(TouchImageView *)touchImageView
  730. {
  731. NSLog(@"signature button clicked;");
  732. __weak __typeof(self)weakSelf = self;
  733. {
  734. long index = touchImageView.tag - CONTROL_BASE;
  735. NSMutableDictionary* control_json = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ];
  736. // CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:trigger];
  737. //
  738. //
  739. // CGRect rect1=[self.view convertRect:cellrect_screen fromView:[[[UIApplication sharedApplication] delegate] window]];
  740. //
  741. // DebugLog(@"convert1 %@",NSStringFromCGRect(rect1));
  742. SignatureListViewController *signatureVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureListViewController"];
  743. signatureVC.title=@"Signatures";
  744. signatureVC.signatureData = self.signatureData;
  745. signatureVC.subType = control_json[@"name"];
  746. signatureVC.can_fill= [control_json[@"can_fill"] boolValue];
  747. // signatureVC.imageView = touchImageView;
  748. signatureVC.blk_Select =^(NSString* file)
  749. {
  750. // NSString* file_name=[file lastPathComponent];
  751. NSData* img_data=[ImageUtils load_img:file];
  752. if(img_data!=nil)
  753. {
  754. UIImage* image=[UIImage imageWithData:img_data];
  755. touchImageView.image = image;
  756. long index = touchImageView.tag - CONTROL_BASE;
  757. weakSelf.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
  758. }
  759. };
  760. signatureVC.blk_Fill =^(NSString* file,bool fillFullDoc)
  761. {
  762. if(weakSelf.blk_Fill)
  763. weakSelf.blk_Fill(file,control_json[@"name"],fillFullDoc);
  764. // for(int j=0;j<[self.controlTemplate[@"count"] intValue];j++)
  765. // {
  766. // NSMutableDictionary* dest =self.controlTemplate[[NSString stringWithFormat:@"control_%d",j]];
  767. // NSString* type = dest[@"type"];
  768. // if(![type isEqualToString:@"Signature"])
  769. // continue;
  770. // if([dest[@"name"] isEqualToString:control_json[@"name"]])
  771. // {
  772. // dest[@"value"]=file;
  773. // }
  774. // }
  775. [weakSelf refreshControl];
  776. // // NSString* file_name=[file lastPathComponent];
  777. //
  778. // NSData* img_data=[ImageUtils load_img:file];
  779. //
  780. // if(img_data!=nil)
  781. // {
  782. //
  783. // UIImage* image=[UIImage imageWithData:img_data];
  784. // touchImageView.image = image;
  785. //
  786. // long index = touchImageView.tag - CONTROL_BASE;
  787. // self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
  788. //
  789. // }
  790. };
  791. signatureVC.blk_Add = ^()
  792. {
  793. __block UIImage* signimg=nil;
  794. SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  795. vc.title =[NSString stringWithFormat:@"Signature: %@",control_json[@"name"]];
  796. vc.onReturnImg = ^(UIImage* img)
  797. {
  798. signimg = img;
  799. if(signimg!=nil)
  800. {
  801. NSString* file=[PDFUtils addSignature:signimg to:self.signatureData subType:control_json[@"name"]];
  802. long index = touchImageView.tag - CONTROL_BASE;
  803. self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
  804. touchImageView.image = signimg;
  805. }
  806. };
  807. // orderinfoVC.url_type = URL_REMOTE;
  808. // orderinfoVC.request_url=URL_CARTDELIVERY;
  809. //
  810. // orderinfoVC.params = params;
  811. //
  812. // orderinfoVC.delegate=self;
  813. //
  814. // if(checked.count==count)
  815. // {
  816. // orderinfoVC.have_tail = true
  817. // }
  818. [self.navigationController pushViewController:vc animated:true];
  819. };
  820. UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:signatureVC];
  821. navi.modalPresentationStyle=UIModalPresentationPopover;
  822. UIPopoverPresentationController* popPc = navi.popoverPresentationController;
  823. popPc.permittedArrowDirections = UIPopoverArrowDirectionAny;
  824. popPc.sourceView = touchImageView;
  825. popPc.delegate = nil;
  826. [self presentViewController:navi animated:true completion:nil];
  827. //// menu.selector = self.selector;
  828. ////
  829. //// menu.selectordelegate = self;
  830. //
  831. // // 1.创建一个UIPopover
  832. // UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]];
  833. //
  834. //
  835. //
  836. // UIPopoverPresentationController
  837. // // 2.设置尺寸
  838. // // popover.popoverContentSize = CGSizeMake(320, 44 * 5);
  839. //
  840. // // 3.从哪里显示出来 --> 指向item
  841. //
  842. // [popover presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:0 animated:YES];
  843. // // [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  844. //
  845. //// self.popover = popover;
  846. // popover pop
  847. //
  848. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  849. }
  850. // __block int tag = touchImageView.tag;
  851. // UIViewController* vc=[RAUtils getViewController :touchImageView];
  852. //
  853. // if(self.editable==true)
  854. // {
  855. //
  856. //
  857. // ImageUploadViewController * uploadvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageUploadViewController"];
  858. //
  859. // // UIImage* img =[self.buttonImg backgroundImageForState:UIControlStateNormal];;
  860. //
  861. // if(self.img_validate)
  862. // uploadvc.img= touchImageView.image;
  863. //
  864. // uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
  865. // {
  866. //
  867. // self.imgs[tag] = url_up;
  868. //
  869. // NSString* newurl=[RAUtils arr2string:self.imgs separator:@"," trim:false];
  870. //
  871. // touchImageView.image=img;
  872. //
  873. // if(self.imgChanged)
  874. // self.imgChanged(url_down,newurl,tag,url_up);
  875. //
  876. // };
  877. //
  878. // [vc.navigationController pushViewController:uploadvc animated:false];
  879. // }
  880. // else
  881. // {
  882. // if(touchImageView.image==nil)
  883. // return ;
  884. // ImageViewController * imagevc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageViewController"];
  885. //
  886. //
  887. // UIImage* img=touchImageView.image;
  888. //
  889. // if(self.img_validate)
  890. // imagevc.image = img;//.imageView.image = [self.buttonImg backgroundImageForState:UIControlStateNormal];
  891. //
  892. // // uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
  893. // // {
  894. // //
  895. // // [self.buttonImg setBackgroundImage:img forState:UIControlStateNormal];
  896. // //
  897. // // if(self.imgChanged)
  898. // // self.imgChanged(url_down,url_up);
  899. // //
  900. // // };
  901. //
  902. // [vc.navigationController pushViewController:imagevc animated:false];
  903. // }
  904. // // bundleVC.content_data = self.bundle_item;
  905. //
  906. }
  907. #pragma mark Responding to keyboard events
  908. - (CGRect)relativeFrameForScreenWithView:(UIView *)v
  909. {
  910. UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
  911. CGRect rect=[v convertRect: v.bounds toView:window];
  912. return rect;
  913. // BOOL iOS7 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 7;
  914. //
  915. // CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
  916. // if (!iOS7) {
  917. // screenHeight -= 20;
  918. // }
  919. // UIView *view = v;
  920. // CGFloat x = .0;
  921. // CGFloat y = .0;
  922. // while (view.frame.size.width != 320 || view.frame.size.height != screenHeight) {
  923. // x += view.frame.origin.x;
  924. // y += view.frame.origin.y;
  925. // view = view.superview;
  926. // if ([view isKindOfClass:[UIScrollView class]]) {
  927. // x -= ((UIScrollView *) view).contentOffset.x;
  928. // y -= ((UIScrollView *) view).contentOffset.y;
  929. // }
  930. // }
  931. // return CGRectMake(x, y, v.frame.size.width, v.frame.size.height);
  932. }
  933. - (void)keyboardWillChangeFrame:(NSNotification *)notification {
  934. NSLog(@"keyboardWillChangeFrame");
  935. }
  936. - (void)keyboardWillShow:(NSNotification *)notification {
  937. NSLog(@"keyboardWillShow");
  938. if(self.keyboard_show)
  939. return;
  940. self.keyboard_show=true;
  941. /*
  942. Reduce the size of the text view so that it's not obscured by the keyboard.
  943. Animate the resize so that it's in sync with the appearance of the keyboard.
  944. */
  945. NSDictionary *userInfo = [notification userInfo];
  946. NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  947. CGSize keyboardSize = [aValue CGRectValue].size;
  948. NSLog(@"keyboard height:%f",keyboardSize.height);
  949. CGRect cellrect_screen = [self relativeFrameForScreenWithView:self.hotTextView];
  950. CGRect rect_screen = [ UIScreen mainScreen ].bounds;
  951. int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height;
  952. if(cellpos>rect_screen.size.height-keyboardSize.height)
  953. {
  954. // self.resize = true;
  955. self.keyboard_h =keyboardSize.height;
  956. CGPoint contentOffsetPoint = self.pdfScrollView.contentOffset;
  957. CGSize contentSize =self.pdfScrollView.contentSize;//frame.size;
  958. CGSize size1 = self.pdfScrollView.bounds.size;
  959. NSLog(@"frame:%@ bound:%@", NSStringFromCGSize(contentSize),NSStringFromCGSize(size1) );
  960. contentSize.height+=self.keyboard_h;
  961. contentOffsetPoint.y+=self.keyboard_h;
  962. self.pdfScrollView.contentSize =contentSize;
  963. self.pdfScrollView.contentOffset=contentOffsetPoint;
  964. }
  965. // self.pdfScrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-self.keyboard_h);
  966. // CGSize tablecontent =self.editorTable.contentSize;
  967. // tablecontent.height=tablecontent.height+self.keyboard_h;
  968. // self.editorTable.contentSize=tablecontent;
  969. // }
  970. // Animate the resize of the text view's frame in sync with the keyboard's appearance.
  971. // [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration];
  972. }
  973. - (void)keyboardWillHide:(NSNotification *)notification {
  974. NSLog(@"keyboardWillHide");
  975. self.keyboard_show=false;
  976. // NSDictionary* userInfo = [notification userInfo];
  977. /*
  978. Restore the size of the text view (fill self's view).
  979. Animate the resize so that it's in sync with the disappearance of the keyboard.
  980. */
  981. // NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
  982. // NSTimeInterval animationDuration;
  983. // [animationDurationValue getValue:&animationDuration];
  984. CGPoint contentOffsetPoint = self.pdfScrollView.contentOffset;
  985. CGSize contentSize =self.pdfScrollView.contentSize;//frame.size;
  986. contentSize.height-=self.keyboard_h;
  987. contentOffsetPoint.y-=self.keyboard_h;
  988. self.pdfScrollView.contentSize=contentSize;
  989. self.pdfScrollView.contentOffset=contentOffsetPoint;
  990. // CGSize tablecontent =self.pdfScrollView.contentSize;
  991. // tablecontent.height=tablecontent.height-self.keyboard_h;
  992. // self.editorTable.contentSize=tablecontent;
  993. // self.pdfScrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
  994. self.keyboard_h= 0;
  995. // NSLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  996. // if(self.resize)
  997. // {
  998. // NSTimeInterval animationDuration = 0.30f;
  999. // CGRect frame = self.view.frame;
  1000. // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
  1001. // // { //还原界面
  1002. // // moveY = prewMoveY;
  1003. // frame.origin.y +=self.ioffset;
  1004. // frame.size. height -=self.ioffset;
  1005. // self.view.frame = frame;
  1006. // // }
  1007. // //self.view移回原位置
  1008. // [UIView beginAnimations:@"ResizeView" context:nil];
  1009. // [UIView setAnimationDuration:animationDuration];
  1010. // self.view.frame = frame;
  1011. // [UIView commitAnimations];
  1012. // //[textField resignFirstResponder];
  1013. // self.ioffset=0;
  1014. // }
  1015. // [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];
  1016. }
  1017. @end