PageViewController.m 46 KB

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