|
@@ -12,10 +12,13 @@
|
|
|
#import "UploadViewController.h"
|
|
#import "UploadViewController.h"
|
|
|
#import <AVFoundation/AVFoundation.h>
|
|
#import <AVFoundation/AVFoundation.h>
|
|
|
#import <AssetsLibrary/AssetsLibrary.h>
|
|
#import <AssetsLibrary/AssetsLibrary.h>
|
|
|
|
|
+#import "TakePhotoPreviewController.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface BasicModeViewController ()<UITextFieldDelegate>
|
|
@interface BasicModeViewController ()<UITextFieldDelegate>
|
|
|
|
|
|
|
|
|
|
+@property (nonatomic,strong) UIImagePickerController *imgPicker;
|
|
|
|
|
+
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
|
@implementation BasicModeViewController
|
|
@implementation BasicModeViewController
|
|
@@ -104,13 +107,58 @@
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
|
|
|
|
|
+// imgPicker.delegate = self;
|
|
|
|
|
+//
|
|
|
|
|
+// imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
|
|
|
|
|
+// imgPicker.allowsEditing = YES;
|
|
|
|
|
+// [self presentViewController:imgPicker animated:YES completion:nil];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 自定义相机控制视图
|
|
|
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
|
|
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
|
|
|
imgPicker.delegate = self;
|
|
imgPicker.delegate = self;
|
|
|
-
|
|
|
|
|
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
|
|
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
|
|
|
- imgPicker.allowsEditing = YES;
|
|
|
|
|
- [self presentViewController:imgPicker animated:YES completion:nil];
|
|
|
|
|
|
|
+ imgPicker.allowsEditing = NO;
|
|
|
|
|
+ imgPicker.showsCameraControls = NO;
|
|
|
|
|
+ UIView* overlay = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 150 , self.view.frame.size.width, 150)];
|
|
|
|
|
+
|
|
|
|
|
+ // Cancel
|
|
|
|
|
+ UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
|
+ cancelBtn.frame = CGRectMake(10, 10, 60, 40);
|
|
|
|
|
+ [cancelBtn setTitle:@"cancel" forState:UIControlStateNormal];
|
|
|
|
|
+ [cancelBtn addTarget:self action:@selector(cancelCameraClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
+ [overlay addSubview:cancelBtn];
|
|
|
|
|
+
|
|
|
|
|
+ // Take
|
|
|
|
|
+ UIButton *takeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
|
+ takeBtn.frame = CGRectMake(80, 10, 60, 40);
|
|
|
|
|
+ [takeBtn setTitle:@"take" forState:UIControlStateNormal];
|
|
|
|
|
+ [takeBtn addTarget:self action:@selector(takePhotoClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
+ [overlay addSubview:takeBtn];
|
|
|
|
|
+
|
|
|
|
|
+ // flash
|
|
|
|
|
+ UIButton *flashBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
|
+ flashBtn.frame = CGRectMake(150, 10, 60, 40);
|
|
|
|
|
+ [flashBtn setTitle:@"Auto" forState:UIControlStateNormal];
|
|
|
|
|
+ [flashBtn addTarget:self action:@selector(flashBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
+ [overlay addSubview:flashBtn];
|
|
|
|
|
+
|
|
|
|
|
+ // camera
|
|
|
|
|
+ UIButton *cameraChangeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
|
+ cameraChangeBtn.frame = CGRectMake(220, 10, 60, 40);
|
|
|
|
|
+ [cameraChangeBtn setTitle:@"change" forState:UIControlStateNormal];
|
|
|
|
|
+ [cameraChangeBtn addTarget:self action:@selector(cameraChangeClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
+ [overlay addSubview:cameraChangeBtn];
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
+ // 相机属性设置得在设置SourceType后设置
|
|
|
|
|
+ imgPicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
|
|
|
|
|
+ //把自定义的view设置到imagepickercontroller的overlay属性中
|
|
|
|
|
+ imgPicker.cameraOverlayView = overlay;
|
|
|
|
|
+
|
|
|
|
|
+ self.imgPicker = imgPicker;
|
|
|
|
|
+ [self presentViewController:imgPicker animated:YES completion:nil];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)showPhotoLibrary {
|
|
- (void)showPhotoLibrary {
|
|
@@ -247,6 +295,63 @@
|
|
|
[self showCamera];
|
|
[self showCamera];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#pragma mark - Image Picker Button Action
|
|
|
|
|
+
|
|
|
|
|
+- (void)cancelCameraClick:(UIButton *)sender {
|
|
|
|
|
+ [self.imgPicker dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)takePhotoClick:(UIButton *)sender {
|
|
|
|
|
+ [self.imgPicker takePicture];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)flashBtnClick:(UIButton *)sender {
|
|
|
|
|
+ UIImagePickerControllerCameraDevice device = self.imgPicker.cameraDevice;
|
|
|
|
|
+ UIImagePickerControllerCameraFlashMode flashMode = self.imgPicker.cameraFlashMode;
|
|
|
|
|
+ NSString *flashMordeString = @"Auto";
|
|
|
|
|
+ switch (flashMode) {
|
|
|
|
|
+ case UIImagePickerControllerCameraFlashModeAuto: {
|
|
|
|
|
+ flashMode = UIImagePickerControllerCameraFlashModeOn;
|
|
|
|
|
+ flashMordeString = @"On";
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case UIImagePickerControllerCameraFlashModeOn: {
|
|
|
|
|
+ flashMode = UIImagePickerControllerCameraFlashModeOff;
|
|
|
|
|
+ flashMordeString = @"Off";
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case UIImagePickerControllerCameraFlashModeOff: {
|
|
|
|
|
+ flashMode = UIImagePickerControllerCameraFlashModeAuto;
|
|
|
|
|
+ flashMordeString = @"Auto";
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ([UIImagePickerController isFlashAvailableForCameraDevice:device]) {
|
|
|
|
|
+ self.imgPicker.cameraFlashMode = flashMode;
|
|
|
|
|
+ [sender setTitle:flashMordeString forState:UIControlStateNormal];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)cameraChangeClick:(UIButton *)sender {
|
|
|
|
|
+ UIImagePickerControllerCameraDevice device = self.imgPicker.cameraDevice;
|
|
|
|
|
+ if (device == UIImagePickerControllerCameraDeviceRear) {
|
|
|
|
|
+ device = UIImagePickerControllerCameraDeviceFront;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ device = UIImagePickerControllerCameraDeviceRear;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ([UIImagePickerController isCameraDeviceAvailable:device]) {
|
|
|
|
|
+ self.imgPicker.cameraDevice = device;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
#pragma mark - Image Picker Delegate
|
|
#pragma mark - Image Picker Delegate
|
|
|
|
|
|
|
|
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
|
|
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
|
|
@@ -254,30 +359,38 @@
|
|
|
UIImage *image = nil;
|
|
UIImage *image = nil;
|
|
|
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
|
|
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
|
|
|
|
|
|
|
|
- image = [info objectForKey:UIImagePickerControllerEditedImage];
|
|
|
|
|
- [picker dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
|
|
|
+ image = [info objectForKey:UIImagePickerControllerOriginalImage];
|
|
|
|
|
+// [picker dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
|
|
|
|
} else if (picker .sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
|
|
} else if (picker .sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
|
|
|
|
|
|
|
|
image = [info objectForKey:UIImagePickerControllerOriginalImage];
|
|
image = [info objectForKey:UIImagePickerControllerOriginalImage];
|
|
|
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
|
}
|
|
}
|
|
|
- NSString *path = [self saveImage:image];
|
|
|
|
|
- if (path) {// 保存成功
|
|
|
|
|
- [self receiveImage:image];
|
|
|
|
|
- NSString *md5 = [RAUtils md5WithFile:path];
|
|
|
|
|
- NSMutableDictionary *photoDic = @{
|
|
|
|
|
- @"photo" : image,
|
|
|
|
|
- @"check" : @(NO),
|
|
|
|
|
- @"file" : [path lastPathComponent],
|
|
|
|
|
- @"md5" : md5,
|
|
|
|
|
- @"path" : path
|
|
|
|
|
- }.mutableCopy;
|
|
|
|
|
- [self.photos addObject:photoDic];
|
|
|
|
|
- self.photoCount++;
|
|
|
|
|
- } else {
|
|
|
|
|
- [RAUtils message_alert:@"Save photo failed" title:@"Warning" controller:self];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ __weak typeof(self) weakself = self;
|
|
|
|
|
+ TakePhotoPreviewController *preVC = (TakePhotoPreviewController *)[self viewControllerInStoryboard:@"Mode" withId:@"TakePhotoPreviewController"];
|
|
|
|
|
+ preVC.photoHandler = ^(UIImage *img){
|
|
|
|
|
+ if (img) {
|
|
|
|
|
+ NSString *path = [weakself saveImage:img];
|
|
|
|
|
+ if (path) {// 保存成功
|
|
|
|
|
+ [weakself receiveImage:img];
|
|
|
|
|
+ NSString *md5 = [RAUtils md5WithFile:path];
|
|
|
|
|
+ NSMutableDictionary *photoDic = @{
|
|
|
|
|
+ @"photo" : img,
|
|
|
|
|
+ @"check" : @(NO),
|
|
|
|
|
+ @"file" : [path lastPathComponent],
|
|
|
|
|
+ @"md5" : md5,
|
|
|
|
|
+ @"path" : path
|
|
|
|
|
+ }.mutableCopy;
|
|
|
|
|
+ [weakself.photos addObject:photoDic];
|
|
|
|
|
+ weakself.photoCount++;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ [RAUtils message_alert:@"Save photo failed" title:@"Warning" controller:weakself];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ preVC.preImage = image;
|
|
|
|
|
+ [self.imgPicker pushViewController:preVC animated:YES];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|