DocumentPageViewController.m 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. //
  2. // DocumentPageViewController.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 "DocumentPageViewController.h"
  9. #import "PageViewController.h"
  10. #import "SignatureListViewController.h"
  11. #import "SignatureViewController.h"
  12. #import "PDFUtils.h"
  13. #import "RANetwork.h"
  14. #import "dbgPageVC.h"
  15. //#import "AFHTTPSessionManager.h"
  16. #import "AppDelegate.h"
  17. #import "RANetwork.h"
  18. #import "RAUtils.h"
  19. //#import "PDFViewController.h"
  20. #import "config.h"
  21. #import "AESCrypt.h"
  22. #import "CustomIOSAlertView.h"
  23. #import "ImageUtils.h"
  24. //#import "RAPDFPage.h"
  25. #import "TextDrawable.h"
  26. #import "ImageDrawable.h"
  27. #import "RectDrawable.h"
  28. #import "RASingleton.h"
  29. @interface DocumentPageViewController ()
  30. @end
  31. @implementation DocumentPageViewController
  32. - (IBAction)onLeftButtonClick:(id)sender {
  33. // if(true)
  34. // {
  35. // self.pdfPath = [[NSBundle mainBundle] pathForResource:@"ZINC_3D_Printing_Guide[1.2].pdf" ofType:nil];
  36. //// [self indexOfViewController:(PageViewController *)viewController]
  37. // [self setupDocument];
  38. // PageViewController* pvc= self.pageViewController.viewControllers[0] ;
  39. // NSUInteger index=[self indexOfViewController:pvc];
  40. // pvc.pageRef = CGPDFDocumentGetPage (self.document , index+1);
  41. // [pvc refreshPage];
  42. // return;
  43. //
  44. // }
  45. // - (NSUInteger) indexOfViewController:(PageViewController *)viewController
  46. UIViewController* pvc = [self pageViewController:self.pageViewController viewControllerBeforeViewController:self.pageViewController.viewControllers[0]];
  47. if(pvc==nil)
  48. return;
  49. __weak typeof(self) weakSelf = self;
  50. [self.pageViewController setViewControllers:@[pvc] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:^(BOOL finished){
  51. long index=[weakSelf indexOfViewController:(PageViewController*)pvc];
  52. if(index==0)
  53. weakSelf.left_button.hidden=true;
  54. else
  55. weakSelf.left_button.hidden=false;
  56. if(index==weakSelf.total_page-1)
  57. weakSelf.right_button.hidden=true;
  58. else
  59. weakSelf.right_button.hidden=false;
  60. }];
  61. // self.pageViewController
  62. }
  63. - (IBAction)onRightButtonClick:(id)sender {
  64. UIViewController* pvc = [self pageViewController:self.pageViewController viewControllerAfterViewController:self.pageViewController.viewControllers[0]];
  65. if(pvc==nil)
  66. return;
  67. __weak typeof(self) weakSelf = self;
  68. [self.pageViewController setViewControllers:@[pvc] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:^(BOOL finished){
  69. long index=[weakSelf indexOfViewController:(PageViewController*)pvc];
  70. if(index==0)
  71. weakSelf.left_button.hidden=true;
  72. else
  73. weakSelf.left_button.hidden=false;
  74. if(index==weakSelf.total_page-1)
  75. weakSelf.right_button.hidden=true;
  76. else
  77. weakSelf.right_button.hidden=false;
  78. }];
  79. }
  80. -(NSMutableDictionary*) templateInit:(NSMutableDictionary*) template
  81. {
  82. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  83. NSString* temp = NSTemporaryDirectory();
  84. NSString* filename =[NSString stringWithFormat:@"%@.png", [[NSUUID UUID] UUIDString]];
  85. NSString* qrpath=[temp stringByAppendingPathComponent:filename];
  86. UIImage* qrimg=[ImageUtils generateBarCode:self.docment_id width:300 height:44];//[QRCodeGenerator qrImageForString:order_code imageSize:240];
  87. bool bwrite=[UIImagePNGRepresentation(qrimg)writeToFile: qrpath atomically:YES];
  88. for(int i=0;i<[template[@"count"] intValue];i++)
  89. {
  90. NSMutableDictionary* page =template[[NSString stringWithFormat:@"page_%d",i]];
  91. for(int j=0;j<[page[@"count"] intValue];j++)
  92. {
  93. NSMutableDictionary* control =page[[NSString stringWithFormat:@"control_%d",j]];
  94. NSString* type = control[@"type"];
  95. NSString* field =control[@"field"];
  96. bool disable = [control[@"disable"] boolValue];
  97. control[@"dirty"]=[NSNumber numberWithBool:false];
  98. if([type isEqualToString:@"Label"])
  99. {
  100. if([field isEqualToString:@"doc_number"])
  101. {
  102. control[@"value"]= self.docment_id;
  103. }
  104. }
  105. else if([type isEqualToString:@"Image"])
  106. {
  107. NSString* name =control[@"name"];
  108. if([name isEqualToString:@"BarCode"])
  109. {
  110. if(bwrite)
  111. control[@"value"]= qrpath;
  112. }
  113. }
  114. else if([type isEqualToString:@"DatePicker"])
  115. {
  116. NSString* name =control[@"aname"];
  117. if([name isEqualToString:@"Today's Date"]/*||[name isEqualToString:@"Handwrite date"]*/)
  118. {
  119. NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
  120. [formatter setDateFormat:@"MM/dd/yyyy"];
  121. NSString* date = [formatter stringFromDate:[NSDate date]] ;
  122. // NSString* cval = control[@"value"];
  123. // if(cval==nil)
  124. control[@"value"]= date;
  125. }
  126. }
  127. else if([type isEqualToString:@"Signature"]&&disable)
  128. {
  129. control[@"value"]= appDelegate.na_path;
  130. }
  131. else if([type isEqualToString:@"TextView"])
  132. {
  133. NSString* name =control[@"aname"];
  134. if([name isEqualToString:@"Agent Name"]||[name isEqualToString:@"Sales Person"])
  135. {
  136. // NSString* cval = control[@"value"];
  137. // if(cval==nil)
  138. control[@"value"]= RASingleton.sharedInstance.agentName;
  139. }
  140. }
  141. }
  142. }
  143. return template;
  144. }
  145. //-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  146. //{
  147. //
  148. //}
  149. -(void) setupTemplete
  150. {
  151. if(self.action==PDFEditActionNew)
  152. self.controlTemplate = [self templateInit:[PDFUtils loadControl:self.templatePath]];
  153. else
  154. self.controlTemplate =[PDFUtils loadControl:self.templatePath];
  155. }
  156. -(void) setupDocument
  157. {
  158. self.signatureData= [[NSMutableDictionary alloc] init];
  159. if(self.document!=nil)
  160. {
  161. CFRelease(self.document);
  162. }
  163. self.document = [PDFUtils OpenPDF:self.pdfPath];
  164. self.total_page = CGPDFDocumentGetNumberOfPages (self.document);
  165. // self.pageViewController rel
  166. }
  167. - (void)viewDidLoad {
  168. [super viewDidLoad];
  169. self.title = self.docment_id;
  170. if(self.hide_control)
  171. [self.ibSave setTitle:@"Upload"];
  172. else
  173. [self.ibSave setTitle:@"Save"];
  174. // self.delegate = self;
  175. // self.dataSource = self;
  176. // 修复初始化时视图向下偏移64点
  177. UIView *v = [[UIView alloc] init];
  178. [self.view insertSubview:v atIndex:0];
  179. [self setupDocument];
  180. [self setupTemplete];
  181. // self.signatureData= [[NSMutableDictionary alloc] init];
  182. //
  183. //
  184. // self.document = [PDFUtils OpenPDF:self.pdfPath];
  185. // self.total_page = CGPDFDocumentGetNumberOfPages (self.document);
  186. // if(self.action==PDFEditActionNew)
  187. // self.controlTemplate = [self templateInit:[PDFUtils loadControl:self.templatePath]];
  188. // else
  189. // self.controlTemplate =[PDFUtils loadControl:self.templatePath];
  190. // self.title = [NSString stringWithFormat:@"%@ [%d/%ld]", self.docment_id,1, self.total_page ];
  191. PageViewController* startingViewController=[self viewControllerAtIndex:0];
  192. // NSArray* viewControllers =[NSArray arrayWithObjects:page_0,nil];
  193. self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
  194. self.pageViewController.delegate = self;
  195. // PageViewController *startingViewController = [self viewControllerAtIndex:0 storyboard:self.storyboard];
  196. NSArray *viewControllers = @[startingViewController];
  197. // dbgPageVC* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"dbgPageVC"];
  198. [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
  199. self.pageViewController.dataSource = self;
  200. [self addChildViewController:self.pageViewController];
  201. [self.view addSubview:self.pageViewController.view];
  202. // Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
  203. CGRect pageViewRect = self.view.bounds;
  204. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
  205. pageViewRect = pageViewRect;//CGRectInset(pageViewRect, 40.0, 40.0);
  206. }
  207. self.pageViewController.view.frame = pageViewRect;
  208. [self.pageViewController didMoveToParentViewController:self];
  209. self.left_button.hidden=true;
  210. self.right_button.hidden=false;
  211. [self.view bringSubviewToFront:self.left_button];
  212. [self.view bringSubviewToFront:self.right_button];
  213. // Do any additional setup after loading the view.
  214. }
  215. -(void) dealloc
  216. {
  217. CFRelease(self.document);
  218. }
  219. - (void)didReceiveMemoryWarning {
  220. [super didReceiveMemoryWarning];
  221. // Dispose of any resources that can be recreated.
  222. }
  223. - (IBAction)OnCancelClicked:(id)sender {
  224. if(self.no_save|| self.hide_control)
  225. {
  226. [self.navigationController popViewControllerAnimated:false];
  227. return;
  228. }
  229. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to cancel the customer ? You will loose all the information you entered." message:nil preferredStyle:UIAlertControllerStyleAlert];
  230. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  231. [self.navigationController popViewControllerAnimated:false];
  232. }];
  233. // [alertControl addAction:actionOne];
  234. [alertControl addAction:alertthree];
  235. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  236. }];
  237. [alertControl addAction:alertcancel];
  238. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  239. [self presentViewController:alertControl animated:YES completion:nil];
  240. }
  241. - (IBAction)onSignatureClicked:(id)sender {
  242. // CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:trigger];
  243. //
  244. //
  245. // CGRect rect1=[self.view convertRect:cellrect_screen fromView:[[[UIApplication sharedApplication] delegate] window]];
  246. //
  247. // DebugLog(@"convert1 %@",NSStringFromCGRect(rect1));
  248. SignatureListViewController *signatureVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureListViewController"];
  249. signatureVC.title=@"Signatures";
  250. signatureVC.signatureData = self.signatureData;
  251. signatureVC.blk_Add = ^()
  252. {
  253. __block UIImage* signimg=nil;
  254. SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  255. vc.onReturnImg = ^(UIImage* img)
  256. {
  257. signimg = img;
  258. // if(signimg!=nil)
  259. // [PDFUtils addSignature:signimg to:self.signatureData];
  260. };
  261. // orderinfoVC.url_type = URL_REMOTE;
  262. // orderinfoVC.request_url=URL_CARTDELIVERY;
  263. //
  264. // orderinfoVC.params = params;
  265. //
  266. // orderinfoVC.delegate=self;
  267. //
  268. // if(checked.count==count)
  269. // {
  270. // orderinfoVC.have_tail = true
  271. // }
  272. [self.navigationController pushViewController:vc animated:true];
  273. };
  274. // signatureVC.blk_Fill =^(NSString* file, bool fillFullDoc)
  275. // {
  276. //
  277. //
  278. // for(int i=0;i<[self.controlTemplate[@"count"] intValue];i++)
  279. // {
  280. // NSMutableDictionary* page =self.controlTemplate[[NSString stringWithFormat:@"page_%d",i]];
  281. // if(!fillFullDoc && i!=self.current_page)
  282. // continue;
  283. // for(int j=0;j<[page[@"count"] intValue];j++)
  284. // {
  285. // NSMutableDictionary* control =page[[NSString stringWithFormat:@"control_%d",j]];
  286. // NSString* type = control[@"type"];
  287. // if(![type isEqualToString:@"Signature"])
  288. // continue;
  289. //
  290. // control[@"value"]=file;
  291. //
  292. //// NSString* name = control[@"aname"];
  293. //// bool required = [control[@"required"] boolValue];
  294. ////
  295. //// if(required==false)
  296. //// continue;
  297. //// if([type isEqualToString:@"Check"])
  298. //// {
  299. //// NSArray* arr = control[@"value"];
  300. //// if(arr.count==0)
  301. //// {
  302. //// ret=false;
  303. ////
  304. //// NSString* msg=[NSString stringWithFormat:@"%u Page %d %@ is missing.",fields.count+1,i+1,name];
  305. //// if(fields.count<15)
  306. //// [fields addObject:msg];
  307. //// else
  308. //// more++;
  309. //// }
  310. ////
  311. //// }
  312. //// else if(/*[type isEqualToString:@"Signature"]||*/[type isEqualToString:@"Image"]||[type isEqualToString:@"Label"])
  313. //// {
  314. //// continue;
  315. //// }
  316. //// else
  317. //// {
  318. //// NSString* str = control[@"value"];
  319. //// if(str.length==0)
  320. //// {
  321. //// ret=false;
  322. //// NSString* msg=[NSString stringWithFormat:@"%lu Page %d %@ is missing.",fields.count+1,i+1,name];
  323. //// if(fields.count<15)
  324. //// [fields addObject:msg];
  325. //// else
  326. //// more++;
  327. //// }
  328. //// }
  329. // }
  330. // }
  331. //
  332. //
  333. // // NSString* file_name=[file lastPathComponent];
  334. ////
  335. //// NSData* img_data=[ImageUtils load_img:file];
  336. ////
  337. //// if(img_data!=nil)
  338. //// {
  339. ////
  340. //// UIImage* image=[UIImage imageWithData:img_data];
  341. //// touchImageView.image = image;
  342. ////
  343. //// long index = touchImageView.tag - CONTROL_BASE;
  344. //// self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
  345. ////
  346. //// }
  347. //
  348. // };
  349. UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:signatureVC];
  350. navi.modalPresentationStyle=UIModalPresentationPopover;
  351. UIPopoverPresentationController* popPc = navi.popoverPresentationController;
  352. popPc.permittedArrowDirections = UIPopoverArrowDirectionUp;
  353. popPc.barButtonItem = sender;
  354. popPc.delegate = nil;
  355. [self presentViewController:navi animated:true completion:nil];
  356. //// menu.selector = self.selector;
  357. ////
  358. //// menu.selectordelegate = self;
  359. //
  360. // // 1.创建一个UIPopover
  361. // UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]];
  362. //
  363. //
  364. //
  365. // UIPopoverPresentationController
  366. // // 2.设置尺寸
  367. // // popover.popoverContentSize = CGSizeMake(320, 44 * 5);
  368. //
  369. // // 3.从哪里显示出来 --> 指向item
  370. //
  371. // [popover presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:0 animated:YES];
  372. // // [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  373. //
  374. //// self.popover = popover;
  375. // popover pop
  376. //
  377. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  378. }
  379. -(CGRect)WindowRect2PDFRect:(CGRect)rect pdf_rect:(CGRect)pdf_rect window_size:(CGSize)window_size
  380. {
  381. CGRect pdf_expand;
  382. float offset_x = 0;
  383. float offset_y = 0;
  384. float scale =1;
  385. if(pdf_rect.size.height>=pdf_rect.size.width)
  386. {
  387. pdf_expand = CGRectMake(0, 0, pdf_rect.size.height*window_size.width/window_size.height, pdf_rect.size.height);
  388. offset_x = (pdf_expand.size.width-pdf_rect.size.width)/2;
  389. scale = pdf_rect.size.height/window_size.height;
  390. }
  391. else
  392. {
  393. pdf_expand = CGRectMake(0, 0, pdf_rect.size.width, pdf_rect.size.width*window_size.height/window_size.width);
  394. offset_y = (pdf_expand.size.height-pdf_rect.size.height)/2;
  395. scale = pdf_rect.size.width/window_size.width;
  396. }
  397. float x=rect.origin.x*scale-offset_x;
  398. float y=rect.origin.y*scale-offset_y;
  399. float width = rect.size.width*scale;
  400. float height = rect.size.height*scale;
  401. return CGRectMake(x, y, width, height);
  402. }
  403. -(void) EndEditing
  404. {
  405. // NSArray* arr =self.pageViewController.viewControllers;
  406. PageViewController *currentViewController = (PageViewController*)self.pageViewController.viewControllers[0];
  407. // PageViewController *currentViewController = (PageViewController*)self.pageViewController.viewControllers[self.current_page];
  408. [currentViewController EndEditing];
  409. }
  410. - (IBAction)onSaveClicked:(id)sender {
  411. [self EndEditing];
  412. if(self.no_save)
  413. {
  414. // [RAUtils message_alert:@"Can not save pending document under offline mode." title:@"Save document" controller:self] ;
  415. [RAUtils message_box:@"Save document" message:@"Can not save pending document under offline mode." completion:nil];
  416. return;
  417. }
  418. if([self verifyData]==false)
  419. return;
  420. NSString* pdffile = nil;
  421. NSString* zipfile = nil;
  422. // NSString* jsonfile = nil;
  423. // for(int l=0;l<1;l++)
  424. {
  425. if(self.hide_control)
  426. {
  427. pdffile = self.pdfPath;
  428. }
  429. else
  430. {
  431. pdffile = [PDFUtils SavePDF:self.controlTemplate source:self.document window_rect:CGRectMake(0, 0, 768, 960) name:self.docment_id isnew:self.action==PDFEditActionNew];
  432. }
  433. zipfile=[RANetwork prepareUploadFile:pdffile json:self.controlTemplate];
  434. //jsonfile = [ACNetwork getjsonPath:zip];
  435. }
  436. __weak typeof(self) weakSelf = self;
  437. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  438. if(appDelegate.accessMode == AppAccessModeOffline)
  439. {
  440. NSMutableDictionary * json = [[NSMutableDictionary alloc]init];
  441. json[@"json"]=@"json.json";
  442. json[@"pdf"]=pdffile.lastPathComponent;
  443. json[@"zip"]=zipfile.lastPathComponent;
  444. json[@"serial"]=[json[@"zip"] stringByDeletingPathExtension];
  445. json[@"create_by"]=RASingleton.sharedInstance.user;
  446. json[@"agent_name"]=[self extract_data:@"sales_person"];
  447. json[@"doc_number"]=[self extract_data:@"doc_number"];
  448. json[@"job_date"]=[self extract_data:@"job_date"];
  449. json[@"customer_name"]=[self extract_data:@"customer_name"];
  450. json[@"signed_date"]=[self extract_data:@"signed_date"];
  451. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  452. NSMutableArray * arr_pending = [[defaults arrayForKey:@"pending_doc"] mutableCopy];
  453. if(arr_pending==nil)
  454. arr_pending = [[NSMutableArray alloc]init];
  455. [arr_pending addObject:json];
  456. [defaults setObject:arr_pending forKey:@"pending_doc"];
  457. [defaults synchronize];
  458. [weakSelf.navigationController popViewControllerAnimated:false];
  459. if(weakSelf.OnSave)
  460. weakSelf.OnSave(pdffile,@"");
  461. }
  462. else
  463. {
  464. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving" completion:^{
  465. PopWaitAlert* pop =[RAUtils waiting_pop:@"Saving..." completion:nil];
  466. [RANetwork request_save_document:zipfile isnew:self.action==PDFEditActionNew completionHandler:^(NSMutableDictionary *result) {
  467. NSDictionary* json = result;
  468. [pop hide];
  469. if([[json valueForKey:@"result"] intValue]==2)
  470. {
  471. [weakSelf.navigationController popViewControllerAnimated:false];
  472. if(weakSelf.OnSave)
  473. weakSelf.OnSave(pdffile,json[@"subject"]);
  474. }
  475. else
  476. {
  477. // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save document" controller:self] ;
  478. if(self.hide_control)
  479. {
  480. //提交离线合同
  481. // [RAUtils message_alert:@"Can not upload pending documents please try again later." title:@"Save document" controller:self] ;
  482. [RAUtils message_box:@"Save document" message:@"Can not upload pending documents please try again later." completion:nil];
  483. return;
  484. }
  485. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Create Customer" message:@"Can not create new customer on server, do you want to create an offline document?" preferredStyle:UIAlertControllerStyleAlert];
  486. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  487. __block NSString* offline_docnumber =[RANetwork offline_docnumber];
  488. if(offline_docnumber==nil)
  489. {
  490. // [RAUtils message_alert:@"Offline document number prefix not found, Please check your user name and make sure you had signed in at least once." title:@"Create Customer" controller:self] ;
  491. [RAUtils message_box:@"Create Customer" message:@"Offline document number prefix not found, Please check your user name and make sure you had signed in at least once." completion:nil];
  492. return;
  493. }
  494. [appDelegate SwitchToOffline:RASingleton.sharedInstance.user];
  495. NSMutableDictionary * json = [[NSMutableDictionary alloc]init];
  496. json[@"json"]=@"json.json";
  497. json[@"pdf"]=pdffile.lastPathComponent;
  498. json[@"zip"]=zipfile.lastPathComponent;
  499. json[@"serial"]=[json[@"zip"] stringByDeletingPathExtension];
  500. json[@"create_by"]=RASingleton.sharedInstance.user;
  501. json[@"agent_name"]=[self extract_data:@"sales_person"];
  502. json[@"doc_number"]=[self extract_data:@"doc_number"];
  503. json[@"job_date"]=[self extract_data:@"job_date"];
  504. json[@"customer_name"]=[self extract_data:@"customer_name"];
  505. json[@"signed_date"]=[self extract_data:@"signed_date"];
  506. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  507. NSMutableArray * arr_pending = [[defaults arrayForKey:@"pending_doc"] mutableCopy];
  508. if(arr_pending==nil)
  509. arr_pending = [[NSMutableArray alloc]init];
  510. [arr_pending addObject:json];
  511. [defaults setObject:arr_pending forKey:@"pending_doc"];
  512. [defaults synchronize];
  513. [weakSelf.navigationController popViewControllerAnimated:false];
  514. if(weakSelf.OnSave)
  515. weakSelf.OnSave(pdffile,@"");
  516. }];
  517. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  518. DebugLog(@"Cancel");
  519. }];
  520. [alertControl addAction:actionOne];
  521. [alertControl addAction:alertthree];
  522. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  523. [self presentViewController:alertControl animated:YES completion:nil];
  524. }
  525. }];
  526. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  527. //
  528. // NSDictionary* json = nil;
  529. //
  530. //
  531. //
  532. // json = [RANetwork save_document:zipfile isnew:self.action==PDFEditActionNew];
  533. //
  534. // dispatch_async(dispatch_get_main_queue(), ^{
  535. //
  536. //
  537. //// [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  538. //// [waitalert dismissViewControllerAnimated:YES completion:^{
  539. // [pop hide];
  540. // if([[json valueForKey:@"result"] intValue]==2)
  541. // {
  542. //
  543. //
  544. // [weakSelf.navigationController popViewControllerAnimated:false];
  545. // if(weakSelf.OnSave)
  546. // weakSelf.OnSave(pdffile,json[@"subject"]);
  547. //
  548. //
  549. // }
  550. // else
  551. // {
  552. // // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save document" controller:self] ;
  553. //
  554. // if(self.hide_control)
  555. // {
  556. // //提交离线合同
  557. //// [RAUtils message_alert:@"Can not upload pending documents please try again later." title:@"Save document" controller:self] ;
  558. //
  559. // [RAUtils message_box:@"Save document" message:@"Can not upload pending documents please try again later." completion:nil];
  560. // return;
  561. // }
  562. //
  563. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Create Customer" message:@"Can not create new customer on server, do you want to create an offline document?" preferredStyle:UIAlertControllerStyleAlert];
  564. //
  565. //
  566. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  567. // __block NSString* offline_docnumber =[RANetwork offline_docnumber];
  568. // if(offline_docnumber==nil)
  569. // {
  570. //// [RAUtils message_alert:@"Offline document number prefix not found, Please check your user name and make sure you had signed in at least once." title:@"Create Customer" controller:self] ;
  571. //
  572. // [RAUtils message_box:@"Create Customer" message:@"Offline document number prefix not found, Please check your user name and make sure you had signed in at least once." completion:nil];
  573. // return;
  574. // }
  575. // [appDelegate SwitchToOffline:RASingleton.sharedInstance.user];
  576. //
  577. //
  578. // NSMutableDictionary * json = [[NSMutableDictionary alloc]init];
  579. //
  580. // json[@"json"]=@"json.json";
  581. // json[@"pdf"]=pdffile.lastPathComponent;
  582. // json[@"zip"]=zipfile.lastPathComponent;
  583. // json[@"serial"]=[json[@"zip"] stringByDeletingPathExtension];
  584. //
  585. //
  586. //
  587. // json[@"create_by"]=RASingleton.sharedInstance.user;
  588. //
  589. //
  590. // json[@"agent_name"]=[self extract_data:@"sales_person"];
  591. // json[@"doc_number"]=[self extract_data:@"doc_number"];
  592. // json[@"job_date"]=[self extract_data:@"job_date"];
  593. // json[@"customer_name"]=[self extract_data:@"customer_name"];
  594. // json[@"signed_date"]=[self extract_data:@"signed_date"];
  595. //
  596. //
  597. //
  598. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  599. // NSMutableArray * arr_pending = [[defaults arrayForKey:@"pending_doc"] mutableCopy];
  600. // if(arr_pending==nil)
  601. // arr_pending = [[NSMutableArray alloc]init];
  602. // [arr_pending addObject:json];
  603. // [defaults setObject:arr_pending forKey:@"pending_doc"];
  604. // [defaults synchronize];
  605. //
  606. //
  607. // [weakSelf.navigationController popViewControllerAnimated:false];
  608. // if(weakSelf.OnSave)
  609. // weakSelf.OnSave(pdffile,@"");
  610. //
  611. //
  612. // }];
  613. //
  614. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  615. // DebugLog(@"Cancel");
  616. // }];
  617. // [alertControl addAction:actionOne];
  618. //
  619. // [alertControl addAction:alertthree];
  620. //
  621. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  622. //
  623. //
  624. // [self presentViewController:alertControl animated:YES completion:nil];
  625. //
  626. // }
  627. //// }];
  628. // // if([[logout_json valueForKey:@"result"] intValue]==2)
  629. // // {
  630. // // self.welcomeLabel.text=@"Not sign in";
  631. // // // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  632. // // [bbitem setTitle:@"Sign in"];
  633. // //
  634. // // self.buttonHIC.enabled = false;
  635. // // self.buttonSRL.enabled = false;
  636. // // self.coverView.hidden = false;
  637. // // }
  638. // // else
  639. // // {
  640. // // [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
  641. // // }
  642. //
  643. //
  644. //
  645. //
  646. // });
  647. // });
  648. // }];
  649. }
  650. }
  651. -(void) addSignature :(UIImage*) img to:(NSMutableDictionary*)signatureData
  652. {
  653. if(true)
  654. {
  655. NSString* newfile=[self saveTempSignature:UIImagePNGRepresentation(img)];
  656. int newidx = [self.signatureData[@"count"] intValue];
  657. // [@"file"]= newfile;
  658. NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
  659. item[@"file"]=newfile;
  660. signatureData[[NSString stringWithFormat:@"item_%d",newidx]] = item;
  661. signatureData[@"count"]=[NSNumber numberWithInt:newidx+1];
  662. }
  663. }
  664. -(NSString *) saveTempSignature:(NSData *) image
  665. {
  666. NSString* tempDir = NSTemporaryDirectory();
  667. NSString *saveFileName=[NSString stringWithFormat:@"%@.png",[[NSUUID UUID ] UUIDString] ] ;
  668. NSString *newFilePath=[tempDir stringByAppendingPathComponent:saveFileName];
  669. bool bsuccess=[image writeToFile:newFilePath atomically:YES];
  670. if(bsuccess)
  671. {
  672. return newFilePath;
  673. }
  674. else
  675. {
  676. return nil;
  677. }
  678. }
  679. /*
  680. #pragma mark - Navigation
  681. // In a storyboard-based application, you will often want to do a little preparation before navigation
  682. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  683. // Get the new view controller using [segue destinationViewController].
  684. // Pass the selected object to the new view controller.
  685. }
  686. */
  687. - (PageViewController *)viewControllerAtIndex:(NSUInteger)index
  688. {
  689. //Return the RAPDFViewController for the given index.
  690. if ((self.total_page == 0 )|| (index > self.total_page) ) {
  691. return nil;
  692. }
  693. //Create a new view controller and pass suitable data.
  694. // PageViewController *PageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
  695. PageViewController *PageViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"PageViewController"];
  696. PageViewController.pageRef = CGPDFDocumentGetPage (self.document , index+1);
  697. PageViewController.pageIndex = index;
  698. PageViewController.hide_control = self.hide_control;
  699. __weak typeof(self) weakSelf = self;
  700. __weak typeof(PageViewController) weakpage = PageViewController;
  701. PageViewController.chg_Contract =^(NSString* file)
  702. {
  703. self.pdfPath = [[NSBundle mainBundle] pathForResource:file ofType:nil];
  704. // [self indexOfViewController:(PageViewController *)viewController]
  705. [self setupDocument];
  706. // PageViewController* pvc= self.pageViewController.viewControllers[0] ;
  707. NSUInteger index=[self indexOfViewController:weakpage];
  708. weakpage.pageRef = CGPDFDocumentGetPage (self.document , index+1);
  709. [weakpage refreshPage];
  710. return;
  711. };
  712. PageViewController.blk_Fill = ^(NSString* file,NSString* subtype,bool fillFullDoc)
  713. {
  714. for(int i=0;i<[weakSelf.controlTemplate[@"count"] intValue];i++)
  715. {
  716. NSMutableDictionary* page =weakSelf.controlTemplate[[NSString stringWithFormat:@"page_%d",i]];
  717. if(!fillFullDoc && i!=weakSelf.current_page)
  718. continue;
  719. for(int j=0;j<[page[@"count"] intValue];j++)
  720. {
  721. NSMutableDictionary* dest =page[[NSString stringWithFormat:@"control_%d",j]];
  722. NSString* type = dest[@"type"];
  723. if(![type isEqualToString:@"Signature"])
  724. continue;
  725. if([dest[@"disable"] boolValue])
  726. continue;
  727. if([dest[@"name"] isEqualToString:subtype])
  728. {
  729. dest[@"value"]=file;
  730. }
  731. }
  732. }
  733. // NSString* file_name=[file lastPathComponent];
  734. //
  735. // NSData* img_data=[ImageUtils load_img:file];
  736. //
  737. // if(img_data!=nil)
  738. // {
  739. //
  740. // UIImage* image=[UIImage imageWithData:img_data];
  741. // touchImageView.image = image;
  742. //
  743. // long index = touchImageView.tag - CONTROL_BASE;
  744. // self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
  745. //
  746. // }
  747. };
  748. PageViewController.page_controlTemplate = self.controlTemplate[[NSString stringWithFormat:@"page_%lu",(unsigned long)index]];
  749. PageViewController.doc_controlTemplate = self.controlTemplate;
  750. PageViewController.signatureData = self.signatureData;
  751. //PageViewController.pdfview = [self.pagePDF objectAtIndex:index];
  752. /*
  753. PageViewController.pdfview = [[PDFView alloc]initWithFrame:self.view.frame atPage:index];
  754. [PageViewController.view addSubview:PageViewController.pdfview];
  755. DebugLog(@"index = %d",index);
  756. */
  757. return PageViewController;
  758. }
  759. - (NSUInteger) indexOfViewController:(PageViewController *)viewController
  760. {
  761. return viewController.pageIndex;//[self.pagePDF indexOfObject:viewController.pdfview];
  762. }
  763. - (NSString*) extract_data:(NSString*)field_name
  764. {
  765. for(int p=0;p<[self.controlTemplate[@"count"] intValue];p++)
  766. {
  767. NSDictionary* page=self.controlTemplate[[NSString stringWithFormat:@"page_%d",p]];
  768. for(int c=0;c<[page[@"count"] intValue];c++)
  769. {
  770. NSDictionary* control=page[[NSString stringWithFormat:@"control_%d",c]];
  771. if([control[@"field"] isEqualToString:field_name])
  772. {
  773. return control[@"value"]==nil?@"":control[@"value"];
  774. }
  775. }
  776. }
  777. return @"";
  778. }
  779. #pragma mark verify data
  780. - (UIView *)createDemoView:(NSString*) msg
  781. {
  782. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  783. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  784. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  785. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  786. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  787. titleLabel.text=@"Missing fields:";
  788. titleLabel.numberOfLines = 0;
  789. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  790. // titleLabel.textAlignment = NSTextAlignmentRight;
  791. titleLabel.textAlignment = NSTextAlignmentCenter;
  792. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  793. CGSize sizetitle =[RAUtils sizeWithFont:@"Missing fields:" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  794. // CGSize sizetitle = [@"Missing fields:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  795. //[titleLabel sizeToFit];
  796. // titleLabel.center.x = demoView.center.x;
  797. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  798. [demoView addSubview:titleLabel];
  799. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  800. lineLabel.font = [UIFont boldSystemFontOfSize:17];
  801. lineLabel.text=msg;
  802. lineLabel.numberOfLines = 0;
  803. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  804. constraintkey = CGSizeMake(260, 20000.0f);
  805. CGSize sizemsg = [RAUtils sizeWithFont:msg font:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  806. // CGSize sizemsg = [msg sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  807. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  808. //[lineLabel sizeToFit];
  809. [demoView addSubview:lineLabel];
  810. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  811. return demoView;
  812. }
  813. -(bool) verifyData
  814. {
  815. if(NO_SAVE_VERIFY)
  816. return true;
  817. // return true;
  818. bool ret=true;
  819. int more=0;
  820. NSMutableArray* fields=[[NSMutableArray alloc] init];
  821. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  822. for(int i=0;i<[self.controlTemplate[@"count"] intValue];i++)
  823. {
  824. NSMutableDictionary* page =self.controlTemplate[[NSString stringWithFormat:@"page_%d",i]];
  825. for(int j=0;j<[page[@"count"] intValue];j++)
  826. {
  827. NSMutableDictionary* control =page[[NSString stringWithFormat:@"control_%d",j]];
  828. NSString* type = control[@"type"];
  829. NSString* name = control[@"aname"];
  830. bool required = [control[@"required"] boolValue];
  831. bool skip_verify = [control[@"skip_verify"] boolValue];
  832. if(required==false || [type.lowercaseString isEqualToString:@"ignor"])
  833. continue;
  834. if(skip_verify&& appDelegate.skip_verify)
  835. continue;
  836. if([type isEqualToString:@"Check"])
  837. {
  838. NSArray* arr = control[@"value"];
  839. if(arr.count==0)
  840. {
  841. ret=false;
  842. NSString* msg=[NSString stringWithFormat:@"%ld. Page %d: %@",fields.count+1,i+1,name];
  843. if(fields.count<15)
  844. [fields addObject:msg];
  845. else
  846. more++;
  847. }
  848. }
  849. else if(/*[type isEqualToString:@"Signature"]||*/[type isEqualToString:@"Image"]||[type isEqualToString:@"Label"])
  850. {
  851. continue;
  852. }
  853. else
  854. {
  855. NSString* str = control[@"value"];
  856. if(str.length==0)
  857. {
  858. ret=false;
  859. NSString* msg=[NSString stringWithFormat:@"%lu. Page %d: %@",fields.count+1,i+1,name];
  860. if(fields.count<15)
  861. [fields addObject:msg];
  862. else
  863. more++;
  864. }
  865. }
  866. }
  867. }
  868. if(ret==false)
  869. {
  870. if(more>0)
  871. {
  872. NSString* msg=[NSString stringWithFormat:@"And %d more missing fields.",more];
  873. [fields addObject:@"......"];
  874. [fields addObject:msg];
  875. }
  876. NSString* missfields=[fields componentsJoinedByString:@"\n"];
  877. NSString* msg = [NSString stringWithFormat:@"%@",missfields];
  878. CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
  879. // Add some custom content to the alert view
  880. [alertView setContainerView:[self createDemoView:msg]];
  881. // Modify the parameters
  882. [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"OK", nil]];
  883. //[alertView setDelegate:self];
  884. // You may use a Block, rather than a delegate.
  885. [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
  886. // DebugLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);
  887. [alertView close];
  888. }];
  889. // [alertView setUseMotionEffects:true];
  890. // And launch the dialog
  891. [alertView sizeToFit];
  892. [alertView show];
  893. }
  894. return ret;
  895. }
  896. #pragma mark - Page View Controller Data Source
  897. - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
  898. {
  899. NSUInteger index = [self indexOfViewController:(PageViewController *)viewController];
  900. if ((index == 0 ) || (index == NSNotFound)){
  901. return nil;
  902. }
  903. // self.current_page= index;
  904. index--;
  905. return [self viewControllerAtIndex:index];
  906. }
  907. - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
  908. {
  909. NSUInteger index = [self indexOfViewController:(PageViewController *)viewController];
  910. if (index == NSNotFound)
  911. {
  912. return nil;
  913. }
  914. // self.current_page= index;
  915. index++;
  916. if (index == self.total_page){
  917. return nil;
  918. }
  919. return [self viewControllerAtIndex:index];
  920. }
  921. #pragma mark - UIPageViewController delegate methods
  922. - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed
  923. {
  924. DebugLog(@"didFinishAnimating");
  925. long index=[self indexOfViewController:pageViewController.viewControllers[0]];
  926. if(index==0)
  927. self.left_button.hidden=true;
  928. else
  929. self.left_button.hidden=false;
  930. if(index==self.total_page-1)
  931. self.right_button.hidden=true;
  932. else
  933. self.right_button.hidden=false;
  934. // self.title = [NSString stringWithFormat:@"%@ [%ld/%ld]", self.docment_id,((PageViewController*)self.pageViewController.viewControllers[0]).pageIndex+1, self.total_page ];
  935. }
  936. - (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation {
  937. if (true/*||UIInterfaceOrientationIsPortrait(orientation) || ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)*/)
  938. {
  939. // In portrait orientation or on iPhone: Set the spine position to "min" and the page view controller's view controllers array to contain just one view controller. Setting the spine position to 'UIPageViewControllerSpineLocationMid' in landscape orientation sets the doubleSided property to YES, so set it to NO here.
  940. UIViewController *currentViewController = self.pageViewController.viewControllers[0];
  941. NSArray *viewControllers = @[currentViewController];
  942. __weak typeof(self) weakSelf = self;
  943. [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished){
  944. long index=[weakSelf indexOfViewController:(PageViewController*)currentViewController];
  945. if(index==0)
  946. weakSelf.left_button.hidden=true;
  947. else
  948. weakSelf.left_button.hidden=false;
  949. if(index==weakSelf.total_page-1)
  950. weakSelf.right_button.hidden=true;
  951. else
  952. weakSelf.right_button.hidden=false;
  953. }];
  954. self.pageViewController.doubleSided = NO;
  955. return UIPageViewControllerSpineLocationMin;
  956. }
  957. // // In landscape orientation: Set set the spine location to "mid" and the page view controller's view controllers array to contain two view controllers. If the current page is even, set it to contain the current and next view controllers; if it is odd, set the array to contain the previous and current view controllers.
  958. // PageViewController *currentViewController = self.pageViewController.viewControllers[0];
  959. // NSArray *viewControllers = nil;
  960. //
  961. // NSUInteger indexOfCurrentViewController = [self indexOfViewController:currentViewController];
  962. // if (indexOfCurrentViewController == 0 || indexOfCurrentViewController % 2 == 0) {
  963. // UIViewController *nextViewController = [self pageViewController:self.pageViewController viewControllerAfterViewController:currentViewController];
  964. // viewControllers = @[currentViewController, nextViewController];
  965. // } else {
  966. // UIViewController *previousViewController = [self pageViewController:self.pageViewController viewControllerBeforeViewController:currentViewController];
  967. // viewControllers = @[previousViewController, currentViewController];
  968. // }
  969. // [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
  970. //
  971. //
  972. // return UIPageViewControllerSpineLocationMid;
  973. }
  974. @end