// // AddExtDocumentViewController.m // Granite Expo eSign // // Created by Ray on 01/03/2017. // Copyright © 2017 United Software Applications, Inc. All rights reserved. // #import "AddExtDocumentViewController.h" #import "MenuViewController.h" #import "RAMenu.h" #import "ImageUtils.h" #import "const.h" #import "RAUtils.h" #import "ACNetwork.h" #import "PDFViewController.h" @interface AddExtDocumentViewController () @end @implementation AddExtDocumentViewController - (void)viewDidLoad { [super viewDidLoad]; self.editDocNumber.text = self.doc_number; if(self.doc_number.length>0) { self.editDocNumber.enabled = false; self.btnScan.enabled = false; } self.edgesForExtendedLayout = UIRectEdgeNone; if(self.arr_documents==nil) self.arr_documents = [[NSMutableArray alloc]init]; if (self.is_present) { UIBarButtonItem *closeButton =nil; closeButton=[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic] style:UIBarButtonItemStylePlain target:self action:@selector( onCloseClick:)]; self.navigationItem.rightBarButtonItem = closeButton; } // else { // [self dismissViewControllerAnimated:YES completion:nil]; // } // { // // // // } // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)onCloseClick:(id)sender { [self dismissViewControllerAnimated:false completion:nil]; } - (IBAction)onScanClicked:(id)sender { } - (IBAction)onAddImageClicked:(id)sender { __weak typeof(self) weakself = self; UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add Image From" message:nil preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) { // textField.text = self.save_name; // // // }]; UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Album" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSUInteger sourceType=UIImagePickerControllerSourceTypePhotoLibrary; UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = weakself; imagePickerController.allowsEditing = YES; imagePickerController.sourceType = sourceType; [self presentViewController:imagePickerController animated:YES completion:^{}]; }]; UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"Take a photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { return; } NSUInteger sourceType=UIImagePickerControllerSourceTypeCamera; UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = weakself; imagePickerController.allowsEditing = YES; imagePickerController.sourceType = sourceType; [self presentViewController:imagePickerController animated:YES completion:^{}]; }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]; [alertControl addAction:actionOne]; [alertControl addAction:action2]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) [self presentViewController:alertControl animated:YES completion:nil]; return; NSMutableArray* menuItem = [NSArray arrayWithObjects:@"aaa",@"bbb",nil]; UIView* v= sender; RAMenu * menu= [[RAMenu alloc]initWithFrame:CGRectMake(v.frame.origin.x, v.frame.origin.y, 120, 88)]; // menu.backgroundColor= [UIColor whiteColor]; menu.arr_menuItems = menuItem; [self.view addSubview:menu]; menu.hidden = false; return; MenuViewController *menuVC = [[MenuViewController alloc]init]; menuVC.arr_menuItems = [menuItem mutableCopy]; // // menuVC.title=@"menu"; // signatureVC.signatureData = self.signatureData; // // signatureVC.blk_Add = ^() // { // // __block UIImage* signimg=nil; // SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"]; // // vc.onReturnImg = ^(UIImage* img) // { // // // signimg = img; // // // if(signimg!=nil) // // [PDFUtils addSignature:signimg to:self.signatureData]; // // // // // }; // // // orderinfoVC.url_type = URL_REMOTE; // // orderinfoVC.request_url=URL_CARTDELIVERY; // // // // orderinfoVC.params = params; // // // // orderinfoVC.delegate=self; // // // // if(checked.count==count) // // { // // orderinfoVC.have_tail = true // // } // // [self.navigationController pushViewController:vc animated:true]; // // // // }; UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:menuVC]; navi.modalPresentationStyle=UIModalPresentationPopover; UIPopoverPresentationController* popPc = navi.popoverPresentationController; popPc.permittedArrowDirections = UIPopoverArrowDirectionUp; popPc.sourceView = sender; popPc.delegate = nil; [self presentViewController:navi animated:true completion:nil]; } - (IBAction)onAddFileClicked:(id)sender { } - (IBAction)onUploadClicked:(id)sender { NSString* docNumber = self.editDocNumber.text; if(docNumber.length==0) { [RAUtils alert_view:@"Document number can not be empty." title:@"Upload"]; return; } NSString* zipfile = nil; NSMutableArray* arr_files= [[NSMutableArray alloc]init]; for(int i=0;i *)info { // self.dirty = true; /*-------------------------------相机拍照--------------------------------------*/ if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage]; image=[ImageUtils img_compress:image kbsize:512]; NSString *path = NSTemporaryDirectory(); NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",[[NSUUID UUID] UUIDString]]]; [UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath atomically:YES]; NSMutableDictionary* item = [[NSMutableDictionary alloc]init]; item[@"type"]=@"image"; item[@"url"]= filePath; item[@"file_name"]= [filePath lastPathComponent]; [self.arr_documents addObject:item]; [self.tableView reloadData]; [picker dismissViewControllerAnimated:YES completion:^{ }]; } else if (picker .sourceType == UIImagePickerControllerSourceTypePhotoLibrary) { /** * UIImagePickerControllerEditedImage 取得的是被编辑过的图片,需要allowsEditing设置为YES * UIImagePickerControllerOriginalImage 取得的是相册中原始图片 */ UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage]; image=[ImageUtils img_compress:image kbsize:512]; NSString *path = NSTemporaryDirectory(); NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",[[NSUUID UUID] UUIDString]]]; [UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath atomically:YES]; NSMutableDictionary* item = [[NSMutableDictionary alloc]init]; item[@"type"]=@"image"; item[@"url"]= filePath; item[@"file_name"]= [filePath lastPathComponent]; [self.arr_documents addObject:item]; [self.tableView reloadData]; [picker dismissViewControllerAnimated:YES completion:nil]; } } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ [picker dismissViewControllerAnimated:YES completion:nil]; // [picker presentViewController:cameraPicker animated:YES completion:nil]; // DebugLog(@"%s",__FUNCTION__); } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end